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

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


The
processing-instruction()
construct can also be written with empty parentheses, in which case it will match any processing instruction. As an alternative, you can provide a name within the parentheses, in which case it will only match processing instructions with that name. For compatibility with XPath 1.0, the name can optionally be written in quotes, as a string literal. This means you can match an

processing instruction using either of the constructs:

processing-instruction(xml-stylesheet)

processing-instruction(“xml-stylesheet”)

The two forms are precisely equivalent, except that using an invalid name is an error in the first case but not the second (you just won't select anything).

Matching Elements and Attributes

The syntax for matching elements and attributes is more complex, because it allows you to take advantage of the type information attached to these nodes as a result of schema validation. The type annotation of an element or attribute node may be any type defined in an XML Schema, or a built-in type. In the case of attributes, it must be a simple type, for elements it can be either a simple or a complex type. All simple types are allowed, including list types and union types. However, although any type defined in a schema can appear as a node annotation, the only types you can refer to directly are those that:

  • have a name (that is, they are not anonymous types, which means they must be defined in top-level type definitions in the schema), and
  • are declared in a schema that has been imported in the static context of the XPath expression. In XSLT this is achieved using the

    declaration.

Here's the basic syntax for element and attribute tests (it is organized slightly differently from the official W3 C grammar):

Expression
Syntax
ElementTest
BasicElementTest |
SchemaElementTest
AttributeTest
BasicAttributeTest |
SchemaAttributeTest
BasicElementTest
element
(
( ElementNameOrWildCard
(
,
TypeName
?
?)?
)?
)
BasicAttributeTest
attribute
(
( AttribNameOrWildcard
(
,
TypeName)?
)?
)

Other books

The Debt 2 by Kelly Favor
The Field of Fight: How We Can Win the Global War Against Radical Islam and Its Allies by Lieutenant General (Ret.) Michael T. Flynn, Michael Ledeen
Inside Threat by Jason Elam, Steve Yohn
Small Treasures by Kathleen Kane (Maureen Child)
Trigger Point by Matthew Glass
The Woman by David Bishop
Stormdancer by Jay Kristoff
The Six Swan Brothers by Adèle Geras
The Saint Goes On by Leslie Charteris