Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The construct
node()
is the most general item type here: it matches any item that is a node.
Note, however, that if you use
node()
on its own as a step in a path expression or as an XSLT match pattern, it is short for
child::node()
and will only match nodes that are found on the child axis. The only nodes that can be found on the child axis are elements, text nodes, comments, and processing instructions.
The constructs
comment()
and
text()
are straightforward: they match comment nodes and text nodes, respectively.
For matching document nodes, you can write the test
document-node()
, which matches any document node, or you can be more specific. If you include an
ElementTest
within the parentheses, then this
ItemType
will only match a document node that satisfies the following two conditions:
This construct allows you to test what can be loosely called the “document type”, for example, you can test whether an input document returned by the
doc()
function is an invoice, by writing:
if (doc(“inv.xml”) instance of document-node(schema-element(mf:invoice))) …
This construct tests whether the document node is labeled as an invoice, as the result of previous validation. If the document has not been validated, the result will be false, whether or not validation would succeed if attempted. The way you control whether
doc()
invokes validation depends on the XSLT processor you are using. With Saxon, you can control it using the options
-val:lax
or
-val:strict
on the command line, or on a per-document basis using parameters appended to the URI. With AltovaXML, the document will be validated if it has an
xsi:schemaLocation
attribute.
Because the same syntax is used in XSLT patterns (described in the next chapter), you can also use it in template rules: