This example demonstrates use of the RANGE predicate. The first element always has a ordinal number of 1.
Find captions of figures that are referenced by <figref> elements in the chapter of "zoo.xml" with title "Frogs".
document("zoo.xml")/chapter[title =
XQuery has allowed for a
List the names of the
/emp[rating =
Here the query locates, where the employees having a “poor” rating, the name of the employees by looking up another emp element having a “mgr” attribute.
In the document "zoo.xml", find <tiger> elements in the namespace defined by www.abc.com/names that contain any supplement in the namespace defined by
www.xyz.com/names:
NAMESPACE abc = "www.abc.com/names" NAMESPACE xyz = "www.xyz.com/names" document("zoo.xml")//abc:tiger[xyz:*]
Here query provides syntax for URIs. A default namespace can also be specified as in this last example:
NAMESPACE DEFAULT = "www.abc.com/names" NAMESPACE xyz = "www.xyz.com/names" document("zoo.xml")//tiger[xyz:*]
Element constructors
The typical use of an element constructor is that it is nested inside another expression that binds one or more variables.
Generate an <emp> element containing an "empid" attribute and nested <name> and <job> elements. The values of the attribute and nested elements are specified by variables that are bound in other parts of the query:
<emp empid = $id> <name> $n </name> ,
42 The XML Files: Development of XML/XSL Applications Using WebSphere Studio