Re: [xsl] xsl:namespace

Subject: Re: [xsl] xsl:namespace
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 22 Feb 2009 08:11:48 -0500
At 2009-02-20 18:32 +0100, Jesper Tverskov wrote:
So wee still need some good examples of why xsl:namespace can be

How about when creating an XSLT stylesheet from a ISO/IEC 19757-3 Schematron schema?

Schematron has an element-based namespace declaration, and here is an example of use:

<schema xmlns="";
  <title>Business rules for maximum total value</title>
  <ns prefix="cbc"
  <ns prefix="cac"
  <phase id="only-phase">
    <active pattern="code-list-rules"/>
    <active pattern="total-limit"/>
  <include href="total-limit-constraint.sch"/>
  <include href="order-constraints.sch"/>

Since the namespaces are only ever used in XPath expressions in attributes, there is no way result tree serialization will detect the need to create a namespace declaration. This isn't cosmetic ... it is absolutely required that the stylesheet creating the XSLT from the Schematron schema dynamically create a namespace declaration.

When using XSLT 1.0 one creates dummy attributes on the document element that trigger the need for a namespace declaration, which then has scope through the entire stylesheet. The dummy attribute is ignored. With access to a node-set() extension, one can create the dummy attribute in a result tree fragment and then copy that one node to the document element. But without such an extension you have to create the dummy attribute to trigger the declaration on the document element.

When using XSLT 2.0 one can use <xsl:namespace> on the generated stylesheet's document element to have scope through the entire stylesheet.

To me that makes <xsl:namespace> a very valuable instruction, and not only cosmetic.

I hope this helps.

. . . . . . . . . .. Ken

Upcoming hands-on  XQuery, XSLT, UBL & code list training classes:
Brussels, BE 2009-03;  Prague, CZ 2009-03,
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread