[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:namespace

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

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="http://purl.oclc.org/dsdl/schematron"
        defaultPhase="only-phase">
  <title>Business rules for maximum total value</title>
  <ns prefix="cbc"
      uri="urn:oasis:names:draft:ubl:schema:xsd:CommonBasicComponents-2"/>
  <ns prefix="cac"
      uri="urn:oasis:names:draft:ubl:schema:xsd:CommonAggregateComponents-2"/>
  <phase id="only-phase">
    <active pattern="code-list-rules"/>
    <active pattern="total-limit"/>
  </phase>
  <include href="total-limit-constraint.sch"/>
  <include href="order-constraints.sch"/>
</schema>

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, http://www.xmlprague.cz
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.