S
S2
hello all, i can't explain this... can someone help me?
this is my xml:
<hello>
<one>
<paragraph>p1</paragraph>
</one>
</hello>
i'd like to change the <hello> element: i want to give it a namespace
and add an atribute. what i want is this:
-------------
<x:hello y:an_attribute="a value for an_attribute"
xmlns:x="some_new_namespace" xmlns:y="other_ns">
<one>
<paragraph>p1</paragraph>
</one>
</x:hello>
-------------
the stylesheet i am using is
-------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl
utput method="xml" indent="yes"/>
<xsl
aram name="element_localname" />
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="local-name() = $element_localname">
<xsl:element name="{$element_localname}"
namespace="some_new_namespace">
<xsl:attribute name="an_attribute" namespace="other_ns">a
value for an_attribute</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:when>
<!-- copy the rest as is -->
<xsl
therwise>
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl
therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
-------------
but what i get is
-------------
<?xml version="1.0" encoding="UTF-8"?>
<ns0:hello xmlns:ns0="other_ns" ns0:an_attribute="a value for an_attribute">
<one>
<paragraph>p1</paragraph>
</one>
</ns0:hello>
this is my xml:
<hello>
<one>
<paragraph>p1</paragraph>
</one>
</hello>
i'd like to change the <hello> element: i want to give it a namespace
and add an atribute. what i want is this:
-------------
<x:hello y:an_attribute="a value for an_attribute"
xmlns:x="some_new_namespace" xmlns:y="other_ns">
<one>
<paragraph>p1</paragraph>
</one>
</x:hello>
-------------
the stylesheet i am using is
-------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl
<xsl
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="local-name() = $element_localname">
<xsl:element name="{$element_localname}"
namespace="some_new_namespace">
<xsl:attribute name="an_attribute" namespace="other_ns">a
value for an_attribute</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:when>
<!-- copy the rest as is -->
<xsl
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
-------------
but what i get is
-------------
<?xml version="1.0" encoding="UTF-8"?>
<ns0:hello xmlns:ns0="other_ns" ns0:an_attribute="a value for an_attribute">
<one>
<paragraph>p1</paragraph>
</one>
</ns0:hello>