Can't match namespace nodes with <xsl:template match>
Posted: Tue Jul 11, 2006 8:35 pm
I'm doing an XML to XML conversion using the identiy transformation code piece first before processing the namespace nodes. For some reason the sky:datasource tags aren't being matched at all. If I remove the sky: namespace, then I can match them after also removing it from the XSL style sheet. In the sample below i'm trying to add an element called <sky:testnode> inside the <sky:datasource> node(s). When I run the XSL everything is copied and passed through, but the new element is never added.
Here is my XML:
Here is my XSL stylesheet:
After the new element is copied, I need strip out the unwanted xmlns:sky attribute that was added inside the new node.
Here is my XML:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="NamespaceMatching.xsl"?>
<sky:item xmlns:sky="http://tempuri.com/item">
<sky:datasource id="LikertScale">
<sky:dataitem text="Unimportant" value="0"/>
<sky:dataitem text="Don't Care" value="1"/>
<sky:dataitem text="Important" value="2"/>
</sky:datasource>
<sky:datasource id="LikertScale2">
<sky:dataitem text="Unimportant" value="3"/>
<sky:dataitem text="Don't Care" value="4"/>
<sky:dataitem text="Important" value="5"/>
</sky:datasource>
</sky:item>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sky="http://ctlt.wsu.edu/skylight/sky">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- the standard identity transformation -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sky:datasource">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:element name="sky:testnode"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>