Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Examples
The following are examples of valid
NCNames
:
A |
alpha |
Π |
ℵ |
_ system-id |
iso-8859-1 |
billing.address |
Straßenüberführung |
E A |
_ … _ --- _ … _ |
I have seen an example of an XML document that used
_
on its own as an element name, but it is not something I would recommend.
XSLT Usage
QNames are also used in XSLT stylesheets in a number of other contexts, outside the scope of XPath expressions. They are used both to refer to elements in the source document (for example, in
There are also some situations where QNames can be constructed dynamically as a result of evaluating an expression. They are used, for example, in
key()
and
format-number()
functions to refer to objects (keys and decimal-formats, respectively) defined in the stylesheet. QNames constructed at runtime are never used to match names in the source document, and they are never used to match template names, variable names, mode names, or attribute set names in the stylesheet; these references must all be fixed names.
Whether the QName is written statically in the stylesheet, or whether it is constructed dynamically, if the name has a prefix then the prefix must be declared by a namespace declaration on some surrounding element in the stylesheet module. For example:
Here the namespace is declared on the actual element that uses the prefix, but it could equally be any ancestor element.
The actual element in the source document does not need to have the tag
math:formula
, it can use any prefix it likes (or even the default namespace) provided that in the source document the element name is in the namespace URI
http://math.org/
.
If the
QName
does not have a prefix, then the rules are more complicated, and there are three possibilities:
the name is assumed to be in the namespace declared using the
xpath-default-namespace
attribute on the