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

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

In fact there are five different ways that an element in the result tree can acquire namespace nodes:

  • When an element is copied from a source tree using an

    or

    instruction, its namespace nodes are also copied, unless this is suppressed by writing
    copy-namespaces=“no”
    .
  • When a literal result element is processed, all the namespace nodes that are in scope for this element in the stylesheet are copied to the result tree, unless this is suppressed using the
    [xsl:]exclude-result-prefixes
    attribute on some containing element. This attribute is described in the entry for

    on page 471.
  • Namespace nodes for namespaces used in element and attribute names are automatically created by the namespace fixup process.
  • When an element is created in the result tree as a child of another element, whether by using

    ,

    ,

    , or a literal result element, then unless the parent element was created using the option
    [xsl:]inherit-namespaces=“no”
    ,
    the child element inherits (acquires a copy of) all the namespace nodes on its new parent element, provided they don't conflict with its existing namespace nodes.
  • Namespace nodes can be created manually using the

    instruction.

So the

instruction is needed only if none of the other mechanisms creates the required namespace declaration.

The namespace fixup process does not automatically create namespace nodes in respect of elements or attributes that have QName-valued content, even when there is a schema that describes the content as a QName. The reason for this is to allow namespace fixup and schema validation to operate as separate processes. Suppose that the schema defines the type of attribute
start
as being an
xs:QName
, and that you want to create the attribute
start=“my:root”
. Schema validation takes the string value of this attribute as input, checks that the namespace prefix
my
is declared, and generates firstly the typed value of this attribute (a QName consisting of the local name
root
and the namespace URI corresponding to prefix
my
), and secondly the type annotation of the attribute as an
xs:QName
. So the namespace node has to be created before schema validation takes place. This means it cannot be done by an automatic namespace fixup process, because at the time namespace fixup takes place, the attribute node has no type annotation, so you don't yet know that it's an
xs:QName
.

Other books

44: Book Six by Jools Sinclair
Not Alone by Amber Nation
Black Box by Amos Oz
String Bridge by Jessica Bell
One Man's Love by Karen Ranney
Smash & Grab by Amy Christine Parker
A Perfect Spy by John le Carre