Passing the context car to the function : context « XQuery « XML






Passing the context car to the function


File: Data.xml


<order>
  <car model="A">
    <id>1111</id>
    <name language="en">name 1</name>
  </car>
  <car model="B">
    <id>2222</id>
    <name language="en">name 2</name>
  </car>
  <car model="B">
    <id>8888</id>
    <name language="en">name 3</name>
  </car>
</order>


File: Query.xquery

declare function local:prod2ndDigit($prod as element()?) as xs:string? {
    substring($prod/id, 2, 1)
};

doc("Data.xml")//car[local:prod2ndDigit(.) > '5']


Output:

<?xml version="1.0" encoding="UTF-8"?>
<car model="B">
    <id>8888</id>
    <name language="en">name 3</name>
  </car>

 








Related examples in the same category