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
6.41Mb size Format: txt, pdf, ePub
ads


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)?
)?
)
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.41Mb size Format: txt, pdf, ePub
ads

Other books

Charlotte's Web by E. B. White
The Sacred Combe by Thomas Maloney
In Medias Res by Yolanda Wallace
Someday Beach by Jill Sanders
Vaclav & Lena by Haley Tanner
La espada y el corcel by Michael Moorcock
False Finder by Mia Hoddell
Powers of the Six by Kristal Shaff
Invisible Chains by Benjamin Perrin