copenndthagen
copenndthagen

Reputation: 50810

Issues with using xsl:value-of select as HTML attribute value

I am having a .jsp file where I have the code;

<span title="<xsl:value-of select='$fullName' />">Some text</span>

I have declared

<xsl:param name="fullName"/>

Now I get an error for the title attribute value used above.

If I use the same statement <xsl:value-of select='$fullName' /> as HTML text, it works fine

e.g. <span><xsl:value-of select='$fullName' /></span> works fine

My question is how do I make the xsl:value-of select work as attribute value?

Upvotes: 1

Views: 2240

Answers (1)

Tim C
Tim C

Reputation: 70648

To use a value as an attribute, you have two options. Firstly, you can use the xsl:attribute element

<span>
   <xsl:attribute name="title"><xsl:value-of select="$fullName" /></xsl:attribute>
</span>

You could also make use of 'Attribute Value Templates' which are often preferred as they can make it more readable

<span title="{$fullName}">Some Text</span>

(The curly braces indicate the 'AVT' in this case).

Both methods should give you the output you desire.

Upvotes: 6

Related Questions