Embedding the where clause : where « XQuery « XML






Embedding the where clause


File: Data.xml


<order>
  <car model="A">
    <id>0001</id>
    <name language="en">name 1</name>
  </car>
  <car model="B">
    <id>0002</id>
    <name language="en">name 2</name>
  </car>
  <car model="B">
    <id>0003</id>
    <name language="en">name 3</name>
  </car>
  <car model="C">
    <id>0004</id>
    <name language="en">name 4</name>
  </car>
</order>


File: Query.xquery

let $sortedProds := for $prod in doc("Data.xml")//car
                    where $prod/@model = "B" or $prod/@model = "C"
                    order by $prod/name
                    return $prod
for $sortedProd at $count in $sortedProds
return <p>{$count}. {data($sortedProd/name)}</p>


Output:

<?xml version="1.0" encoding="UTF-8"?>
<p>1. name 2</p>
<p>2. name 3</p>
<p>3. name 4</p>

 








Related examples in the same category

1.where with or operator
2.A where clause with multiple expressions