Namespaces are created automatically when writing out elements and attributes are which need relevant namespaces. If other namespace declarations are required in the output, xsl:namespace element comes handy.
|
XSLT
<xsl:stylesheet xmlns:r="rrrrrr" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/aaa"> <r:aaa> <xsl:namespace name="s">ssssss</xsl:namespace> <xxx> <xsl:namespace name="{substring-before(.,':')}" select="substring-after(.,':')"/> </xxx> </r:aaa> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa>y:yyyyyy</aaa> |
Output
<r:aaa xmlns:r="rrrrrr" xmlns:s="ssssss"> <xxx xmlns:y="yyyyyy"/> </r:aaa> |
| Previous chapter: | Multiple Outputs |
| Next chapter: | Keys |
| Previous page: | Namespace aliasing |
| Next page: | Discovering available namespaces on the element |