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

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
7.61Mb size Format: txt, pdf, ePub
ads
ElementNameOrWildcard
ElementName |
*
AttribNameOrWildcard
AttributeName |
*
ElementName
QName
AttributeName
QName
TypeName
QName

We will come back to the
SchemaElementTest
and
SchemaAttributeTest
later. The meaning of this syntax doesn't leap out from the page, so it's best to explain it by listing all the possible cases. The general form is
element (
NAME
,
TYPE
)
, where
NAME
defines conditions on the name of the element, and
TYPE
defines conditions on its type annotation.

Here are the rules for matching elements:

Test
Matches
element()
Any element node.
element(*)
Any element node.
element(N)
Any element node whose name is
N
. In a path expression this is equivalent to just writing the element name
N
on its own, but in contexts where a
SequenceType
is required, it provides a way of saying that a value must be an element with a particular name, whether or not this name is defined in any schema.
element(*,T)
Any element node whose type annotation shows it to be valid according to the rules of schema type
T
. The type
T
can be a simple type or a complex type, but it must be a named type that is defined in an imported schema (this allows a built-in type, of course).
If the element has the attribute
xsi:nil = “true”
, then it matches only if the type name
T
in the sequence type descriptor is followed by a question mark.
element(N,T)
Any element node whose name is
N
and that is annotated as an instance of schema type
T
. This combines the previous two options into a single condition.

The rules for matching attributes are very similar, but they are simpler because attributes cannot be marked as nillable:

Test
Matches
attribute()
Any attribute node.
attribute(*)
Any attribute node.
attribute(N)
Any attribute node whose name is
N
.
attribute(*,T)
Any attribute node whose type annotation shows it to be valid according to the rules of schema type
T
. The type
T
must always be a named simple type that is defined in an imported schema (this allows a built-in type, of course).
attribute(N,T)
Any attribute node whose name is
N
and that is annotated as an instance of the schema type
T
.

Using Global Element and Attribute Declarations

The basic element and attribute tests described in the previous section allow you to test an element or attribute node according to its name and its type annotation, provided that the type annotation is a named simple or complex type in the schema. It's very common, however, to find that elements are declared in a schema using global element declarations and with an anonymous type: to take an example from the schema for XSLT 2.0 stylesheets:


  

     

       

          

            

          

       

     

  


The syntax
element(E,
T)
doesn't work in this case, because the type is anonymous. Instead, the construct
schema-element(S)
can be used. This matches any element that has been validated against the global element declaration named
S
in the schema. It's not necessary that the name of the element should be
S
; it can also be an element in the substitution group of
S
.

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

Other books

Passionate Tides by Johnson, J.N
Having Everything Right by Stafford, Kim; Pyle, Robert Michael;
O'Farrell's Law by Brian Freemantle
The Ghost of Ernie P. by Betty Ren Wright
Revenge by Sierra Rose
Kate Moore by An Improper Widow