Intermingled for and let clauses : let « XQuery « XML






Intermingled for and let clauses


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 $doc := doc("Data.xml")
for $prod in $doc//car
let $prodmodel := $prod/@model
let $prodName := $prod/name
where $prodmodel = "B" or $prodmodel = "A"
return $prodName

Output:

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

 








Related examples in the same category

1.Adding a let clause
2.Using a let clause with a range expression
3.Let stateCt