I asked similiar to this question before but I'm still not handled this case correctly, firstly I'm saying that I am new to this XQuery language so configure the recursive strategy is really hard for me for now.
XQuery Sample Code to be executed :
declare variable $stuff :=
<doc>
<embed-session>
<session>
<title>Fred Smith</title>
<session>
<title>Ahmet Özcan</title>
<session>
<title>Erman Bey</title>
</session>
</session>
</session>
</embed-session>
</doc>;
declare function local:change($node as node()) as element()
{
typeswitch($node)
case element() return
element { fn:node-name($node) } {
attribute title {data($node/title)},
$node/session ! local:change(.)
}
default return $node
};
local:change($stuff/embed-session/session)
The output of the code :
<session title="Fred Smith">
<session title="Ahmet Özcan">
<session title="Erman Bey"/>
</session>
</session>
It seems that it fits with my expectations but if I add one more embed session node to my stuff variable for example :
<embed-session>
<session>
<title>Ferhat Bey</title>
</session>
</embed-session>
to my parameter of the function it says that : [XPTY0004] Cannot treat item() sequence as node(): (..., )
The expected output of the code after add the embed-session mentioned below :
<session title="Fred Smith">
<session title="Ahmet Özcan">
<session title="Erman Bey"/>
</session>
</session>
<session title="Ferhat Bey"/>
I know it is sequence but why I couldn't assign sequence to node as parameter ?