XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (498 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
5.99Mb size Format: txt, pdf, ePub

Usage

The pattern
/
matches any document node. This means that if you have several trees (which will be the case in a stylesheet that uses the
document()
or
doc()
functions described in Chapter 13), the pattern
/
will match the document nodes of each one. This makes it difficult to write different template rules to match the document nodes of different trees. There are a few ways around this problem:

  • If your documents are of different types (that is, if they use different schemas, or different top-level elements in the same schema), then you can distinguish them using a pattern such as
    document-node(schema-element(invoice))
    or
    document-node(schema-element(purchase-order))
    These constructs are described on page 700 later in the chapter.
  • You can use different modes to process each tree (see the section
    Modes
    on page 247 in Chapter 6).
  • You can start the processing of secondary documents at the element node immediately below the root. A pattern such as
    /item
    will match an item element that is an immediate child of the document node. This kind of pattern is often useful when your stylesheet is dealing with multiple source documents, because it allows you to distinguish them by the name of the document element.

The pattern
/@width
is legal but meaningless; it would match a
width
attribute of the document node, but as the document node cannot have attributes, there is no such node.

To match every

element, use the pattern
para
in preference to
//para
The latter will work (except in non-document trees), but its default priority is different, and it may be less efficient. For the other kinds of
PathPattern
, see
RelativePathPattern
(on this page) and
IdKeyPattern
(page 704) discussed later.

Other books

Bringing Stella Home by Joe Vasicek
Mistress of the Storm by Terri Brisbin
Trackdown (9781101619384) by Reasoner, James
Three Seconds by Anders Roslund, Borge Hellstrom
Moore To Love by Faith Andrews
Darkness Before Dawn by J. A. London
Taming the Alter Ego by Shermaine Williams