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

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

With XML Namespaces 1.1, it is also possible to cancel declarations of non-default namespaces, using an attribute of the form
xmlns:prefix = “”
. This undeclaration, if supported by the XSLT processor, ensures that the literal result element will not have a namespace node for that namespace prefix.

In the result tree, the element created from the literal result element is guaranteed to have a namespace node for every namespace node that was present on the literal result element in the stylesheet, except the following:

  • A namespace node for the XSLT namespace URI
    http://www.w3.org/1999/XSL/Transform
    will not be copied.
  • A namespace node for a namespace declared as an extension instruction namespace will not be copied. A namespace is declared as an extension instruction namespace by including its prefix in the value of the
    [xsl:]extension-element-prefixes
    attribute of the literal result element, or of any enclosing element in the stylesheet. (The attribute must be prefixed with the XSLT namespace if it appears on a literal result element, but must be unprefixed if it appears on an XSLT element.)
  • A namespace node for an excluded namespace will not be copied. A namespace is declared as an excluded namespace by including its prefix in the value of the
    [xsl:]exclude-result- prefixes
    attribute of this literal result element or of any ancestor element in the stylesheet. (Again, the attribute must be in the XSLT namespace when it appears on an element that is
    not
    in the XSLT namespace.)

These exceptions don't apply if the name of the element, or the name of one of its attributes, actually uses one of these namespaces. The system will always ensure that the namespaces used for the element and attributes in the result tree are declared, however hard you try to prevent it. If this isn't what you want, then the chances are you should be generating the element in a different namespace to start with. To achieve this, you might need to use the

instruction instead of using literal result elements.

Consider the following stylesheet:

   version=“2.0”

   xmlns:Date=“java:java.util.Date”

>


    




There are three namespaces in scope for the

element, namely the XSLT namespace, the namespace
java:java.util.Date
, and the default namespace
urn:acme-com:gregorian
. The XSLT namespace is not copied to the result tree, but the other two are. So, the

element added to the result tree is guaranteed to have these two namespaces in scope:
java:java.util.Date
, and
urn:acme-com:gregorian
.

This stylesheet uses two extension functions
Date:new()
and
Date:toString()
. This means that it will not be portable between different XSLT processors.

Other books

Clifton Falls by L A Taylor
Dear Dad by Christian, Erik
Femme by Marshall Thornton
Shadow Keeper by Unknown
Dewey by Vicki Myron, Bret Witter
Beyond a Misty Shore by Lyn Andrews