Reputation: 2277
Im trying to put data from one element to another. I have done an XSL stylesheet thats puts out this two strings.
<fordon pris="129900"><name>Honda</name><modellTyp>1</modellTyp></fordon>
<fordon pris="119000"><name>Nissan</name><modellTyp>2</modellTyp></fordon>
But I want to get the numers ( 1 and 2) inside my modellTyp so the output should be
<modellTyp1>
and <modellTyp2>
This is what my XSL file look like to output the result I have
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ad">
<xsl:element name="fordon">
<xsl:attribute name="pris">
<xsl:copy-of select="price" />
</xsl:attribute>
<xsl:copy-of select="name"/>
<xsl:element name="modellTyp">
<xsl:value-of select="type" />
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thanks in advance.
Upvotes: 2
Views: 301
Reputation: 243529
@lwburk's answer is correct, but there is even a simpler/shorter solution:
<xsl:element name="modellTyp{type}">
<xsl:value-of select="type"/>
</xsl:element>
Upvotes: 1
Reputation: 60414
Dynamically create the element name with curly braces in the Attribute Value Template:
<xsl:element name="{concat('modellTyp', type)}">
<xsl:value-of select="type"/>
</xsl:element>
Upvotes: 1