Re: [xsl] Testing attribute name and replacing them with other attribute name

Subject: Re: [xsl] Testing attribute name and replacing them with other attribute name
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Mon, 05 Sep 2005 19:28:35 +0200
Hi,

Tempore 17:11:04, die 09/05/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Thomas Winkler <thomasm003@xxxxxxxx>:

I want to find some attributes by name and then
replacing them with other attributes (actually doing
language transformation) :

for example

<tshirts size="XXL" brand="Nike" price="14">

should be changed into :

<tshirts lC$nge="XXL" marke="Nike" preis="14">

How can this be done ?

This is a typical job for an identity transformation:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="node()|@*">
	<xsl:copy>
		<xsl:apply-templates select="node()|@*" />
	</xsl:copy>
</xsl:template>

<xsl:template match="@size">
	<xsl:attribute name="lC$nge"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@brand">
	<xsl:attribute name="marke"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@price">
	<xsl:attribute name="preis"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

</xsl:stylesheet>

But perhaps the language-string mapping is already done in some XML file. In that case, you load that in the XSLT.

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+Error, keyboard not foundb press F1 to continueB; , BIOS

Current Thread