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
6.96Mb 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

Fervor by Silver, Jordan
Chasing Circumstance by Redmon, Dina
Alliance Forged by Kylie Griffin
Swimming by Nicola Keegan
The Loner by Joan Johnston
Selected Stories by Katherine Mansfield
Regency 02 - Betrayal by Jaimey Grant
Navy SEAL Captive by Elle James
Once Upon a List by Robin Gold