Skip to Content
Special Edition Using XSLT
book

Special Edition Using XSLT

by Michael Floyd
January 2002
Intermediate to advanced
480 pages
11h 5m
English
Que
Content preview from Special Edition Using XSLT

Positional Predicates

As well as Boolean expressions, predicates can contain numerical expressions.

foo[5] 
foo[last()] 

These predicates match elements based on their document order in the node set.

Imagine this source document:

<person> 
    <name>Mr. Fish</name> 
    <address>The Sea</address> 
    <appearance>Shiny and scaly</appearance> 
<person> 

This expression produces a node set with three element nodes:

/person/* 

You can use a positional predicate on that node set to pull out the second node within it in document order:

/person/*[2] 

The result will be a node set containing just one node, the element <address>.

A more complex example would be to select the first <img> element in an XHTML document:

//img[1] 

The expression //img matches all

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Special Edition Using XML, Second Edition

Special Edition Using XML, Second Edition

- et al. David Gulbransen
XML for Publishers

XML for Publishers

Keith Fahlgren

Publisher Resources

ISBN: 0789725053Purchase book