Obtaining Particular Types of Nodes By Using Node Tests

The node tests allow you to obtain nodes according to their type. Node test is an XPath term. Although a node test looks like a function, it is not a function.

You can use node tests with filters and position specifiers. They resolve to the set of children of the context node that meets the restrictions you specify.

Node tests for XPath 2.0 add to the set of node tests supported for XPath 1.0. Node tests common to both XPath 1.0 and XPath 2.0 are shown in Table 88. Node tests unique to XPath 2.0 are shown in Table 88.

For each p element in the current context, the following query returns its second text child node:

p/text()[2]  

Following is a query that finds the third comment child in each foo element anywhere in the document:

//foo/comment()[3] 

About the Document Object

In the Document Object Model (DOM), a document contains comments, processing instructions, and declarations, as well as the document element. As in XPath, the root node is the root of the DOM tree, and the root node is not the same as the document element. This allows comments, declarations, and processing instructions at the document entity level.

For example, the following query finds all comments at the document entity level. In other words, it finds all comments that are immediate children of the root node.

/comment()  

This query returns the comment at the beginning of the bookstore.xml file:

Getting Nodes of a Particular Type

A query like the following returns all the comments in a document:

//comment() 

The following query returns the third comment in the document.

(//comment()) [3]  

XQuery Talk Blog

Get the latest XQuery news and information at XQuery-Talk - an online community for discussing XQuery technologies, examples, implementations and more. Bookmark this RSS or ATOM feed now!

EDI to XML

Using the DataDirect XML Converters EDI repository, the EDI to XML Conversion module is able to support dozens of EDI standard dialects and message types like EDIFACT, HL7, and X12.

XSLT Debugger

Stylus Studio's XSLT debugger - a requirement for building bug-free XSLT stylesheets and XML data transformation applications. Stylus Studio's XSLT debugger gives you complete visibility and control over the XSLT transformation process.

XML Operations

Using XML Pipeline it's easy to visually specify a series of XML operations to apply on your XML data, including parsing, validating, converting and transforming, according to the needs of your business application.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member