Nested for each loop : for « XQuery « XML






Nested for each loop


File: Query.xquery
<cars>
{for $i in (1 to 5, 7, 8) return
 <group>{ for $a in (1 to ($i - 2)) return<car>{$a}</car>}
 </group>
 }
</cars>


Output:

<?xml version="1.0" encoding="UTF-8"?>
<cars>
   <group/>
   <group/>
   <group>
      <car>1</car>
   </group>
   <group>
      <car>1</car>
      <car>2</car>
   </group>
   <group>
      <car>1</car>
      <car>2</car>
      <car>3</car>
   </group>
   <group>
      <car>1</car>
      <car>2</car>
      <car>3</car>
      <car>4</car>
      <car>5</car>
   </group>
   <group>
      <car>1</car>
      <car>2</car>
      <car>3</car>
      <car>4</car>
      <car>5</car>
      <car>6</car>
   </group>
</cars>

 








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.For each node in certain level
9.For stateCt
10.for and doc() function