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

xsl:namespace

Subject: xsl:namespace
From: Jesper Tverskov <jesper@xxxxxxxxxxx>
Date: Fri, 20 Feb 2009 14:34:46 +0100
 xsl:namespace
I'm trying to make a code example that makes xsl:namespace
understandable. In my opinion one of the most difficult xsl elements.
Now here is my question: Have I succeded?

Output:
   <price xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:type="xs:decimal">23.50</price>

Stylesheet:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
    <xsl:param name="ns-prefix" select="'xs'"/>
    <xsl:param name="ns-identifier"
select="'http://www.w3.org/2001/XMLSchema'"/>

    <xsl:template name="start">
        <test>

<!-- alternative 1 -->
        <xsl:element name="price">
            <xsl:attribute name="xsi:type" select="'xs:decimal'"
namespace="http://www.w3.org/2001/XMLSchema-instance"/>
            <xsl:namespace name="xs"
select="'http://www.w3.org/2001/XMLSchema'"/>
            <xsl:text>23.50</xsl:text>
        </xsl:element>

<!-- alternative 2 -->
        <price xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xml:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:decimal">
            <xsl:text>23.50</xsl:text>
        </price>

<!-- alternative 3 -->
        <price xsi:type="{$ns-prefix}:decimal"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance'">
            <xsl:namespace name="{$ns-prefix}" select="$ns-identifier"/>
            <xsl:text>23.50</xsl:text>
        </price>

        </test>

    </xsl:template>
</xsl:stylesheet>

1) When we create the price element using xsl:element, we only need
xsl:namespace to create the namespace for the attribute value.

2) When we create the price element the literal way we don't need
xsl:namespace. We can put the needed namespace declarations into the
literal element directly. We can even put them in the xsl:stylesheet
element and they will end up in output as we want it.

3) If we want a dynamic solution, we need xsl:namespace even when
creating the output element the literal way. We can now change "xs" to
"xsd" with a parameter from outside.

Cheers,
Jesper Tverskov

http://www.xmlkurser.dk
http://www.xmlplease.com

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.