[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|