BizTalk Utilities CV ,   Jobs ,   Code library  
 
 
[XSLT Reference] [XPath Reference] [Download Reference Download this Reference]

XPath Reference

General intro

An XPath expression contains one or more "location steps", separated by slashes. Each location step has the following form:

axis-name :: node-test [predicate]*

Or in English: an axis name, then two colons, then a node-test and finally zero or more predicates in brackets. We will show a list of valid axes and a list of valid node-sets in this appendix. A predicate is an expression. It exists of values, operators and other XPath expressions.

The XPath axis contains a part of the document, defined from the perspective of the "context node". The node test makes a selection from the nodes on that axis. By adding predicates, it is possible to select a subset from these nodes. If the expression in the predicate returns true, the node remains in the selected set, otherwise it is removed.

XPath defines a set of functions for use in predicates. These are listed in the appendix as well.

Implementations

  • W3C 1.0 specification (recommendation) - Go there
  • MSXML 2.0 (IE5)
  • MSXML 2.6 (January 2000 preview)
  • MSXML 3.0 - Go there
  • MSXML 4.0 - Go there
  • XML classes in .NET Framework class library - Go there

Axes

ShorthandPrimary nodetypew3c1msxml2msxml26msxml3msxml4msxml.NET
childContains all direct children of the context node (that is the children, but not any of the children's children)(default axis)element X X X X X X
parentContains the direct parent node (and only the direct parent node) of the context node. ..element X X X X X X
descendantAll children of the context node, including all children's children recursively //element X X X X X X
ancestorContains the context node's parent node, its parent's parent node etc., all the way up to the document root. If the context node is the root node, the ancestor node is empty.element X X X X X
attributeContains all attributes on the context node. The axis will be empty unless the context node is an element.@attribute X X X X X
ancestor-or-selfIdentical to the ancestor axis, but including the context node itself.element X X X X X
descendant-or-selfIdentical to the descendant axis, but including the context node itself.element X X X X X
selfContains only the context node itself..element X X X X X X
preceding-siblingContains all siblings (children of the same parent node) of the context node that come before the context node in document orderelement X X X X
following-siblingContains all siblings (children of the same parent node) of the context node that come after the context node in document orderelement X X X X
namespaceContains all namespaces available on the context node. This includes the default namespace and the xml namespace (these are automatically declared in any document). The axis will be empty unless the context node is an element.namespace X X X X
followingContains all nodes that come after the context node in the document order. This means that the start tag of the node must come after the closing tag of the context node and therefore excludes the descendants of the context node.element X X X X
precedingContains all nodes that come before the context node in the document order. This includes all elements that are already closed (their closing tag comes before the context node in the document) and therefore excludes all ancestors of the context node. element X X X X

Node tests

w3c1msxml2msxml26msxml3msxml4msxml.NET
*Returns true for all nodes of the primary type of the axis. X X X X X X
comment()Returns true for all comment nodes X X X X X X
literal nameReturns true for all nodes of that name. If the node test is 'PERSON', it returns true for all nodes of name 'PERSON' X X X X X X
node()Returns true for all nodes, except attributes and namespaces X X X X X X
processing-instruction( name? )Returns true for all processing instruction nodes. If a name is passed, returns true only for processing instruction nodes of that name X X X X X X
text()Returns true for all text nodes X X X X X X

Functions

w3c1msxml2msxml26msxml3msxml4msxml.NET
[boolean] X X X X X
[ceiling] X X X X
[concat] X X X X X
[contains] X X X X X
[count] X X X X X
[false] X X X X X
[floor] X X X X
[id] X X X X X X
[lang] X X X X
[last] X X X X X X
[local-name] X X X X X
[name] X X X X X
[namespace-uri] X X X X X
[normalize-space] X X X X X
[not] X X X X X
[number] X X X X X
[position] X X X X X
[round] X X X X
[starts-with] X X X X X
[string] X X X X X
[string-length] X X X X X
[substring] X X X X X
[substring-after] X X X X X
[substring-before] X X X X X
[sum] X X X X
[translate] X X X X X
[true] X X X X X

A few examples of XPath expressions

Select all descending elements from the root

/descendant::*

Select ancestor elements of the context node that are named 'Chapter'

ancestor::Chapter

Select nodes that have more than two direct children of name 'Skip'

/descendant::node()[count(child::Skip) > 2]

Select all Student elements whose name attribute start with an A (using shorthand notation)

//Student[starts-with(@name, 'A')]

Note: You can now download the full content of the XPath reference, the XSLT reference and the DOM reference in one PDF document. This document contains the implementation tables, internal links to navigate through the references, a full linked table of contents. You can use free text search through the whole reference or print as a nicely formatted document. Download here...

© 2000 Teun Duynstee. Shown on TopXML.com. Information used from XSLT and XPath recommendations © W3C and MSDN documentation © Microsoft.
Do you have comments, additions or suggestions, mail me.
 

Recent Jobs

A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En
A Greate Opportunituy as a SQL Deve
An immediate job opportunity as a B

View all Jobs (Add yours)
View all CV (Add yours)



Information Online

swimming pool builder
chicago web site design
spfxmasks
Cheap Web Hosting
conference calling
Juicy couture sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP