tags:

views:

491

answers:

1

How do I create a new HTML tag/node in XSLT ? I get the node/tag name from another variable.

+4  A: 
<xsl:element name="{$ELEMENT_NAME}">
  <xsl:attribute name="{$ATTRIBUTE_NAME}">
    <xsl:value-of select="$ATTRIBUTE_VALUE"/>
  </xsl:attribute>
  <content>
    <goes>
      <here/>
    </goes>
  </content>
</xsl:element>

edit:
You need { and } for the "name" attributes, but not for the "select" attribute.

Read about here.

SORRY! I forgot it myself in first 'version' of the answer.

ivan_ivanovich_ivanoff
One thing: you may want to show how to make the element's name set via a parameter or variable as that is the OP's intention.
Andrew Hare
+1 No need for the attribute example though. I know, I know, but the question was about elements only, and the answer does not gain completeness from it. :)
Tomalak