Using xsl:value-of inside an html tag

by manojgumber

I was working on an xml assignment when I came across this problem. While writing xsl sheet for an displaying an xml file , I had to use <xsl:value-of > element inside an html tag or any other tag. But with normal syntax , things were not working. Stumbling on some books and xslt documentation , I found a way out.

Attribute Value Templates are solution for this problem.

e.g when you use,

<a href='<xsl:value-of select=”/page/results/prevnext/@prevresult”>’ >Previous</a>

It results in errors. The correct way using AVT is

<a href=”{/page/results/prevnext/@prevresult”}>Previous</a>
Note the curly brackets { } which indicate the Attribute Value Template.

AVTs are a convenience method for you to insert the result of an expression

into an attribute value. Otherwise you would have to use the equivalent

long-hand approach:
<a><xsl:attribute name=”href”><xsl:value-of

select=”/page/results/prevnext/@prevresult”/></xsl:attribute>Previous</a>

Hope it is useful !!

Advertisements