For stateCt : for « XQuery « XML






For stateCt


File: Data.xml


<!-- Order input docuCt -->
<order num="00299432" date="2006-09-15" cust="0221A">
  <item dept="A" num="1" quantity="1" color="navy"/>
  <item dept="B" num="2" quantity="1"/>
  <item dept="B" num="3" quantity="2"/>
  <item dept="C" num="4" quantity="1" color="white"/>
  <item dept="C" num="4" quantity="1" color="gray"/>
  <item dept="A" num="1" quantity="1" color="black"/>
</order>



File: Query.xquery

<title>Order Report</title>,
(for $item in doc("Data.xml")//item
 order by $item/@num
 return $item)


Output:

<?xml version="1.0" encoding="UTF-8"?>
<title>Order Report</title>
<item dept="A" num="1" quantity="1" color="navy"/>
<item dept="A" num="1" quantity="1" color="black"/>
<item dept="B" num="2" quantity="1"/>
<item dept="B" num="3" quantity="2"/>
<item dept="C" num="4" quantity="1" color="white"/>
<item dept="C" num="4" quantity="1" color="gray"/>

 








Related examples in the same category

1.Multiple for clauses
2.Multiple variable bindings in one for clause
3.Nested for loop
4.for loop and node text
5.Use for loop
6.for each loop and range
7.for each loop
8.Nested for each loop
9.For each node in certain level
10.for and doc() function