Reputation: 98
I have a code to output options list:
<xsl:template match="*" mode="option">
<xsl:param name="value" select="'value'"/>
<option>
<xsl:attribute name="value" select="./@($value)"/>
<xsl:value-of select="./@name"/>
</option>
</xsl:template>
The question is how can i get an attribute value which name is in variable $value? What should i use instead of not working construction: ./@($value).
Upvotes: 1
Views: 339
Reputation: 167426
If you want to use a parameter or variable value then $value
is all you need, i.e. <xsl:attribute name="value" select="$value"/>
to create an attribute with name value
and with the value of the parameter which is also value
. If you want to read out the value of an attribute named like your parameter then you would use <xsl:attribute name="value" select="@*[local-name() eq $value]"/>
.
You could also consider an attribute value template for brevity:
<option value="{$value}"><xsl:value-of select="@name"/></option>
respectively
<option value="{@*[local-name() eq $value]}"><xsl:value-of select="@name"/></option>
Upvotes: 1