Reputation: 2376
Using xquery 1.0, I want to take a sequence like this;
<foo xml:id="x20"/>
<foo xml:id="x47"/>
<foo xml:id="x3"/>
And collate the ids into a string to put in an attribute of a new element like this;
<bar ids="x20 x47 x3"/>
Is there a way to do it without manually iterating over the input sequence using a FLWOR?
Upvotes: 4
Views: 255
Reputation: 243539
Use:
<bar ids="{/*/*/@xml:id}"/>
When this XQuery is applied on the following XML document (just wrapping the provided XML fragment into a well-formed XML document):
<t>
<foo xml:id="x20"/>
<foo xml:id="x47"/>
<foo xml:id="x3"/>
</t>
the wanted, correct result is produced:
<bar ids="x20 x47 x3"/>
Upvotes: 1
Reputation: 167696
let $s := (<foo xml:id="x20"/>,<foo xml:id="x47"/>,<foo xml:id="x3"/>)
return <bar ids="{$s/@xml:id}"/>
Upvotes: 5