xsl:namespace (3)

  1. namespace_3-input.xml

  2. <?xml version="1.0"?>
  3. <price>23.50</price>
  1. namespace_3-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  4.   <xsl:output indent="yes"/>
  5.   <xsl:template match="price">
  6.     <xsl:element name="price">
  7.       <xsl:attribute name="xsi:type" select="'xs:decimal'" namespace="http://www.w3.org/2001/XMLSchema-instance"/>
  8.       <xsl:namespace name="xs" select="'http://www.w3.org/2001/XMLSchema'"/>
  9.       <xsl:value-of select="."/>
  10.     </xsl:element>
  11.   </xsl:template>
  12. </xsl:stylesheet>
  1. namespace_3-output.xml

  2. <?xml version="1.0"?>
  3. <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>


The above example show how xsl:namespace can be used to create the namespace for a QName as part of content. In our example, a QName, "xs:decimal", is the value of the "xsi:attribute". We have a similar example in the spec. See my tutorial xsl:namespace in XSLT 2.0.

Updated 2009-03-19