Friday, April 29, 2011

XSLT create new HTML tag

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

From stackoverflow
  • <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.

    Andrew Hare : 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.
    Tomalak : +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. :)

0 comments:

Post a Comment