I'm looking to get a custom attribute for anchor tag from xsl.
Is it possible to get the name of the attribute dynamically from xml?
Here is what I tried :
<xsl:attribute name="<xsl:value-of select="id"/>">
<xsl:value-of select="value"/>
</xsl:attribute>
Yes, it is possible. You can pass a variable as name
value.
<xsl:variable name="attributeName" select="id"/>
<xsl:attribute name="{$attributeName}">
<xsl:value-of select="value"/>
</xsl:attribute>
You can simpify the solution from @Savard to
<xsl:attribute name="{id}">
<xsl:value-of select="value"/>
</xsl:attribute>
or if you are using XSLT 2.0, to
<xsl:attribute name="{id}" select="value"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With