I want to append the values of some XML tags, and then append again the result. But I'm having some trouble appending the results, so I only have one final result of appending.
Imagine you have this:
<nodeA>
<nodeB>
<item>1</item>
<item>2</item>
<yesno>blah</yesno>
</nodeB>
<nodeC>
<thing>A</thing>
</nodeC>
</nodeA>
<nodeA>
<nodeB>
<item>3</item>
<item>4</item>
<yesno>blah</yesno>
</nodeB>
<nodeC>
<thing>B</thing>
</nodeC>
</nodeA>
I want to get this result <result>A,1,2,B,3,4</result>
But I get this one: <result>A,1,2</result><result>B,3,4</result>
I've been reading this: http://stackoverflow.com/questions/1739479/xquery-how-to-properly-append-in-for-loop but still I can't make it work. Here is the sample of my code.
let $contador := count(
for $x in $productDoc//*[substring(local-name(.),2,23)="nodeB"]
where not(exists ($x/ns0:yesno))
return
$x)
return
if ($contador = 0) then
<result> </result>
else
for $x in $productDoc//*[substring(local-name(.),2,18)="nodeB"]
where not(exists ($x//ns0:yesno))
return
for $y in $x//*[matches(name(.),'thing')]
let $z := $x//*[matches(name(.),'item')]
return
for $i in $y
let $c := concat($i,",",string-join($z,","))
return
let $d := string-join($c,",")
<result>{ $d }</result>
I suppose what is happening is that I'm appending the partial results wrongly... or in a wrong place, but I don't know where to do it. Maybe I should call this function from another one that makes a string-join of the result. What do u think?