Skip to content

XPath Model Examples

Nico Kutscherauer edited this page Feb 28, 2022 · 1 revision

This page shows some examples how XPath expressions are represented in the model.

Location Steps

XPath:

foo (:or child::foo, child::element(foo):)

Model:

<locationStep axis="child">
   <nodeTest name="foo" kind="element"/>
</locationStep>

with Predicate

XPath:

foo[@bar]

Model:

<locationStep axis="child">
   <nodeTest name="foo" kind="element"/>
   <predicate>
      <locationStep axis="attribute">
         <nodeTest name="bar" kind="attribute"/>
      </locationStep>
   </predicate>
</locationStep>

Operations

Step Operations

XPath:

foo/bar

Model:

<operation type="step">
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <slash/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
</operation>

XPath:

foo/bar/baz

Model:

<operation type="step">
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <slash/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <slash/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
</operation>

Compare Operations

XPath:

foo = bar

Model:

<operation type="compare">
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <eq/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
</operation>

XPath:

foo eq bar

Model:

<operation type="value-compare">
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <eq/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
</operation>

XPath:

foo is bar

Model:

<operation type="node-compare">
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <eq/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
</operation>

Function calls

XPath:

concat(foo, bar, baz)

Model:

<function-call>
   <function name="concat"/>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
   <arg>
      <locationStep axis="child">...</locationStep>
   </arg>
</function-call>

Literals

Strings

XPath:

'foo'

Model:

<string value="foo"/>

Integers

XPath:

123

Model:

<integer value="123"/>

Decimals

XPath:

12.3

Model:

<decimal value="12.3"/>

Other

Variable References

XPath:

$var

Model:

<varRef name="var"/>

Self

XPath:

.

Model:

<self/>

Root

XPath:

/

Model:

<root/>

Empty Sequence

XPath:

()

Model:

<empty/>

Clone this wiki locally