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

Re: Re: xsl:namespace

Subject: Re: Re: xsl:namespace
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Sat, 21 Feb 2009 12:32:10 +0000 (GMT)
Re:  Re: xsl:namespace
Jesper Tverskov wrote:
> Florent writes:

> "I used xsl:namespace almost exclusively in meta-stylesheets."
> I guess that means stylesheets creating stylesheets as
> output. To me that is exciting and novel stuff.

> If you can make a small example of such a meta-stylesheet using
> xsl:namespace, it would save my day.

  Ok.  Let's say we have a document type like the following
excerpt (inspired by a real example I created on a project, but I
can't provide real excerpts):

    <para i18n="total">
       <amount name="price" select="$var/to/amount"/>
    </para>

  All the documents of the enterprise (contracts, invoices, etc.)
are created using this document type.  But those documents are
not used as is in the system, they are transformed to stylesheets
first (by a stylesheet, of course) and those stylesheets are used
by the system to generate actual documents.

  At some point in the generated stylesheet, you will end up with
something like the following:

    <xsl:value-of select="impl:format-amount($var/to/amount)"/>

  I kept this example simple, but the expression can of course
accesses element in some namespaces, use functions in some
namespaces...  So you have to copy all the namespace bindings in
scope on the element 'amount' to the element you copy the
expression in the generated stylesheet (here the xsl:value-of.)

  So in the meta-stylesheet, you would have something like the
following:

    <!-- prefix 'a' is an alias for 'xsl' -->
    <xsl:template match="amount">
       ...
       <a:value-of select="impl:format-amount({ @select })">
          <xsl:sequence select="ms:copy-namespaces(.)"/>
       </a:value-of>
       ...
    </xsl:template>

where ms:copy-namespace() is something like:

    <!-- ...as="namespace-node()" -->
    <xsl:function name="ms:copy-namespace">
       <xsl:param name="ctxt" as="element()"/>
       <xsl:for-each select="in-scope-prefixes($ctxt)">
          <xsl:sequence select=""/>
          <xsl:namespace name="{ . }" select="
              namespace-uri-for-prefix(., $ctxt)"/>
       </xsl:for-each>
    </xsl:function>

  Disclaimer: I wrote those examples in my web browser, but the
idea is there.

  Regards,

--
Florent Georges
http://www.fgeorges.org/

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-2013 All Rights Reserved.