BizTalk Working With XPath – XPath 1.0 Operators and Special Characters Quick Reference

Posted: August 29, 2009 in BizTalk
Tags: , ,

Operators

Boolean, Comparison, and Set Expressions
Filter patterns can contain Boolean expressions, comparison expressions, and set expressions. Shortcuts listed in the following table represent alternative symbols that are provided in this XSL Transformations (XSLT) implementation. This documentation discusses these expression operators.

Operator Description Example
and Logical-and price>9.00 and price<9.90
author[degree and award]
or Logical-or price=9.80 or price=9.70
not() Negation
= Equality price=9.80
author[last-name = "Bob"]
!= Not equal price!=9.80
degree[@from != “Harvard”]
&lt; * Less than price &lt; 9.80
&lt;= * Less than or equal price &lt;= 9.80
book[position() &lt;= 3]
&gt; * Greater than price &gt; 9.80
&gt;= * Greater than or equal price &gt;= 9.80
| Set operation; returns the union of two sets of nodes //book | //cd
Returns a node-set with all book and cd elements

Operators and Special Characters
XPath expressions are constructed using the operators and special characters shown in the following table.

Operator Description Example
/ Child operator; selects immediate children of the left-side collection. When this path operator appears at the start of the pattern, it indicates that children should be selected from the root node. /bookstore
The document element (<bookstore>) of this document.

// Recursive descent; searches for the specified element at any depth. When this path operator appears at the start of the pattern, it indicates recursive descent from the root node. //author
All <author> elements in the document.

. Indicates the current context. ./first-name
All <first-name> elements in the current context node. Note that this is equivalent to the expression in the next row.

.. The parent of the current context node. author[last-name = “Bob” and ../price &gt; 50]
All <author> elements that contain a <last-name> child element whose value is Bob, and a <price> sibling element whose value is greater than 50.

* Wildcard; selects all elements regardless of the element name. author/*
All element children of <author> elements

@ Attribute; prefix for an attribute name. price/@exchange
The exchange attribute of <price> elements within the current context.
@* Attribute wildcard; selects all attributes regardless of name.
: Namespace separator; separates the namespace prefix from the element or attribute name. my:book
The <book> element from the my namespace.
( ) Groups operations to explicitly establish precedence.
[ ] Applies a filter pattern.
+ Performs addition. 6 + 4 result 10
Performs subtraction. 6 – 4 result 2
div Performs floating-point division according to IEEE 754. 8 div 4 result 2
* Performs multiplication. 6 * 4 result 24
mod Returns the remainder from a truncating division. 5 mod 2 result 1

Tags: BizTalk | XPath | XML

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s