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

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

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

and

) and to name and refer to objects within the stylesheet itself, including variables, templates, modes, and attribute sets.

There are also some situations where QNames can be constructed dynamically as a result of evaluating an expression. They are used, for example, in

and

to generate names in the result document, and in the
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:

  • In the case of a name used as the name of a literal result element in the stylesheet, or in a small number of other places, the namespace that's used is the one declared using a default namespace declaration in the stylesheet, in the form
    xmlns = “some.uri”
    . If there is no such declaration, the name is assumed to be in no namespace.
  • In the case of a name used as an element name or type name in an XPath expression, or in certain other contexts such as:
    • an XSLT pattern
    • the
      elements
      attribute of

      or

    • the
      as
      attribute of elements such as

      and

    • the
      type
      attribute of instructions such as

      the name is assumed to be in the namespace declared using the
      xpath-default-namespace
      attribute on the

      element. This can also be overridden on any other element in the stylesheet. If there's no such declaration, the name is assumed to be in no namespace.

  • A name is being “used as an element name” if it appears in an axis step (see Chapter 9) whose axis is anything other than the attribute or namespace axis. Some names appearing in the
    SequenceType
    production used to describe types also fall into this category.
  • Names used to refer to attribute and namespace nodes, as well as the names of variables, functions, and stylesheet objects such as modes, keys, and named templates, are always considered to be in no namespace when they are unprefixed.

Other books

Murder on Amsterdam Avenue by Victoria Thompson
Finding Never by C. M. Stunich
Gay Amish 03 - A Way Home by Keira Andrews
King of Forgotten Clubs by Recchio, Jennifer
This Hallowed Ground by Bruce Catton
The Killables by Gemma Malley