I have a function which returns item()*. The output of this function is something like the following:
<Root>
<Value>
<Year>1999</Year>
<A>50</A>
<B>100</B>
</Value>
<Value>
<Year>2000</Year>
<A>50</A>
<B>100</B>
<Value>
</Root>
This output is supposed to be passed to a second function. I want to be able to parse this and return a different output. I've tried converting the output to a string using fn:parse-xml($output) but I get an error saying No text allowed before root element. However, if I declare a local variable inside the second function and assign it the string output it works.
This works:
declare function function2($outputFromFunction1 as item()*) item()*{
let sToX := fn:parse-xml(" <Root>
<Value>
<Year>1999</Year>
<A>50</A>
<B>100</B>
</Value>
<Value>
<Year>2000</Year>
<A>50</A>
<B>100</B>
<Value>
</Root>")...
};
I am able to parse this variable (for $Value in $sToX/Value...).
Why does it work in this case and not when I use the argument that is passed in?