Last Updated: February 25, 2016
· novalagung

XSL - Passing data as attribute value of tag

For example, you have data like this :

<sometag SomeAttribute="some value" /> 

You want to make value of SomeAttribute as variable that accessible from HTML tag atrribute value. Like <div class="value of SomeAttribute"></div>.

You can use xsl:param. For example, I'm assigning SomeAttribute value to some variable called somevar. The code would be :

<xsl:param name="somevar" select="sometag/@SomeAttribute" />

Normally, to get somevar value, we use :

<xsl:value-of select="$somevar"/>

But to use it as attribute value, we can use :

<div class="{$somevar}"></div>
Say Thanks