Search code examples
xmlxslttags

Create a new tag from attribute


I need an xsl transformation that, given inputs like (with variable number of columns and rows)

<row>
<column inum="1">...</column>
<column inum="2">...</column>
[...]
</row>
<row>
[...]

gives back a structure like

<row>
<column_1>...</column_1>
<column_2>...</column_2>
[...]
</row>
<row>
[...]

I've seen many answers, but all about copying/modifying attributes, not using them to create new tags. Is it possible?


Solution

  • It's a rather trivial exercise:

    <xsl:template match="column">
        <xsl:element name="column_{@inum}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>