I have the following xml:
<subjects>
<subject id="5" name="Maths"/>
<subject id="10" name="English" points="5"/>
<subject id="15" name="Science" points="10" cats="15"/>
</subjects>
and I have the following code:
for $subject in $subjects/subject
return
<subject id="{$subject/@id}">
<foo/>
</subject>
which outputs
<subject id="5"><foo/></subject>
<subject id="10"><foo/></subject>
<subject id="15"><foo/></subject>
However the above code does not show all the attributes of subject. Only id
. Of course I can continue hardcoding more attributes but this won't help if I don't know what the attributes names are.
What I want is something like this:
<subject id="5" name="Maths"><foo/></subject>
<subject id="10" name="English" points="5"><foo/></subject>
<subject id="15" name="Science" points="10" cats="15"><foo/></subject>
I believe the solution would be something like this:
for $subject in $subjects/subject
return
insert-child( <foo/>, $subject)
How do I do this?