Wrapping results in a new element : output « XQuery « XML






Wrapping results in a new element


File: Data.xml

<order>
  <car model="ACC">
    <id>0001</id>
    <name language="en">name 1</name>
  </car>
  <car model="BCC">
    <id>0002</id>
    <name language="en">name 2</name>
  </car>
  <car model="BCC">
    <id>0003</id>
    <name language="en">name 3</name>
  </car>
</order>
File: Query.xquery

<ul>{
  for $car in doc("Data.xml")/order/car
  where $car/@model='ACC'
  order by $car/name
  return $car/name
}</ul>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<ul>
   <name language="en">name 1</name>
</ul>

 








Related examples in the same category

1.Constructing elements using XML-like syntax
2.Adding attributes to results
3.Adding an attribute to an element
4.Removing a child from an element
5.Turning content into markup