This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: adding attribute to copy
- From: Jarno dot Elovirta at nokia dot com
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 26 Sep 2002 09:53:51 +0300
- Subject: RE: [xsl] adding attribute to copy
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
> i need an XSL stylesheet that transforms an XML input so that
> there ist
> he same output
> only one attribute has to be added to one element called <richtext>
> it is the attribute xmlns="..."
> so taht it says <richtext xmlns=""> in the output-
Think again. You're not trying to add an attribute, you're trying to change the default namespace URI of richtext element and all it's children - actually you didn't specify if you wanted to change it for all descendants or just those who have the same NS-URI as richtext originally had. Try something like this
<xsl:variable name="new" select="'http://your.new.and.improved.namespace.uri'" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[local-name() = 'richtext']">
<xsl:element name="{local-name()}" namespace="{$new}">
<xsl:apply-templates select="@*|node()" mode="ns">
<xsl:with-param name="old" select="namespace-uri()" />
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="*[local-name() = 'richtext']" mode="ns">
<xsl:param name="old" />
<xsl:element name="{local-name()}" namespace="{$new}">
<xsl:apply-templates select="@*|node()" mode="ns">
<xsl:with-param name="old" select="namespace-uri()" />
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()" mode="ns">
<xsl:param name="old" />
<xsl:choose>
<xsl:when test="namespace-uri() = $old and self::*">
<xsl:element name="{name()}" namespace="{$new}">
<xsl:apply-templates select="@*|node()" mode="ns">
<xsl:with-param name="old" select="$old" />
</xsl:apply-templates>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="ns">
<xsl:with-param name="old" select="$old" />
</xsl:apply-templates>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
That probably won't handle all cases,
Jarno
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list