XML/Output: Difference between revisions

m
Line 2,749:
=={{header|XQuery}}==
 
First, we create two string sequences (ordered lists), $names and $remarks, through which we then will loop, using a counter, $cntcount, to keep the current iteration index, which we then will apply as XPath predicate to select an item at this index from the second sequence.
 
In the second variant we use a function 'fn:for-each-pair#3', instead of the FLOWR, to accomplish the same task. XML construction is being encapsulated within a callback function here.
Line 2,761:
let $remarks := ("Bubbly: I'm > Tam and <= Emily", 'Burns: "When chapman billies leave the street ..."',"Short &amp; shrift")
return element CharacterRemarks {
for $name at $count in $names
return element Character {
attribute name { $name }
,text { $remarks[$count] }
}
}
}
}
</lang>
 
Line 2,774:
let $names := ("April","Tam O'Shanter","Emily")
let $remarks := ("Bubbly: I'm > Tam and <= Emily", 'Burns: "When chapman billies leave the street ..."',"Short &amp; shrift")
return <CharacterRemarks> {
for $name at $count in $names{
return <Character name='{ for $name}'> {$remarks[at $count]} </Character>in $names
return <Character name='{$name}'> {$remarks[$count]} </Character>
}
}
</CharacterRemarks>
</lang>
 
Line 2,786 ⟶ 2,787:
xquery version "3.1";
 
let $names := ("April","Tam O'Shanter","Emily")
let $remarks := ("Bubbly: I'm > Tam and <= Emily", 'Burns: "When chapman billies leave the street ..."',"Short &amp; shrift")
return element CharacterRemarks {
for-each-pair($names, $remarks, function($name, $remark) {
element Character {
attribute name { $name }
,text { $remark }
,text { $remark }
}
}
})
})
}
}
</lang>
 
Line 2,806 ⟶ 2,807:
let $remarks := ("Bubbly: I'm > Tam and <= Emily", 'Burns: "When chapman billies leave the street ..."',"Short &amp; shrift")
return <CharacterRemarks>
{
{
for-each-pair($names, $remarks, function($name, $remark) {
<Character name='{$name}'> {$remark} </Character>
})
})
}
}
</CharacterRemarks>
</lang>
 
Anonymous user