[xquery-talk] Add value to result before a for loop

Andrew Welch andrew.j.welch at gmail.com
Wed Jul 18 06:04:04 PDT 2012


> I can’t seem to find valid syntax for output of a value before a for loop.
> In this example I want to output a header line ($hdr) to the results.

> let $doc :=
> <doc>
> <item><id>1</id><name>item 1</name></item>
> <item><id>2</id><name>item 2</name></item>
> </doc>
>
> let $hdr := concat('Id',  codepoints-to-string(9), 'Name',
> codepoints-to-string(10))
>
> for $i in $doc/item return
> concat($i/id,  codepoints-to-string(9), $i/name,  codepoints-to-string(10))


let $doc :=
<doc>
<item><id>1</id><name>item 1</name></item>
<item><id>2</id><name>item 2</name></item>
</doc>

return string-join(('Id	Name', $doc/item/concat(id, '	', name)), '
')

-- 
Andrew Welch
http://andrewjwelch.com



More information about the talk mailing list