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

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
11.99Mb size Format: txt, pdf, ePub
ads
  • element()
    matches any element node. This can also be written as
    element(*)
    .
  • attribute()
    matches any attribute node. This can also be written as
    attribute(*)
    .

Now things start to get more complicated, because the other kinds of
KindTest
are concerned with testing for specific types of node as defined in a schema. In general, you will use these
KindTests
only to match nodes in documents that have been validated against a schema.

KindTests for Element Nodes

Let's look first at the options for matching element nodes:

  • element(QName)
    matches any element node whose name is the given
    QName
    . As a pattern, this is exactly the same as writing the
    QName
    on its own. (The reason for providing this syntax is that a
    KindTest
    is allowed in contexts other than patterns; for example, in the
    as
    attribute of an

    element.)
  • schema-element(QName)
    is used to test for an element that matches a top-level element declaration in the schema identified by the given
    QName
    . It's an error to use this form unless you have imported a schema containing this top-level element declaration. For example, if you write
    schema-element(mfg:invoice)
    , then the schema for the
    mfg
    namespace must have been imported, and must include a top-level element declaration of the form
    xs:element name=“invoice”
    .

    The element is considered to match if two conditions are satisfied:

    • Its name is either the same as the
      QName
      , or the name of an element defined in the schema to be a member of the substitution group with the named element as its head.
    • The type of the element node, identified from its type annotation, matches the type defined for this element declaration in the schema. This rule is there because a schema can allow the same name to be used in different contexts with different type definitions.
  • element(*, QName)
    is used to test for an element whose type annotation indicates that it has been successfully validated against the schema-defined type definition identified by the
    QName
    . The
    QName
    can identify a built-in type such as
    xs:dateTime
    , or a type (which may be a simple type or a complex type) that is the subject of a named type definition in an imported schema. The test will match any element that has a type annotation that refers to the named type, or a type derived from the named type by restriction or by extension.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
11.99Mb size Format: txt, pdf, ePub
ads

Other books

The Deadly Embrace by Robert J. Mrazek
Tuna Tango by Steven Becker
The Zebra Wall by Kevin Henkes
Blue Like Elvis by Diane Moody
Holly's Wishes by Karen Pokras