i am trying to pass an xsl variable value to a javascript function.
My xsl variable
<xsl:variable name="title" select="TITLE" />
i'm passing the value like this
<input type="button" value="view" onclick="javascript:openPage('review.html?review=$title')" />
i have tried the above code in different possible ways but i gets errors.
<script type="text/javascript">
function jsV() {
var jsVar = '<xsl:value-of select="TITLE"/>';
return jsVar;
}
</script>
<input type="button" value="view" onclick="javascript:openPage('javascript:jsV()')" />
I also tried
<input type="button" value="view" onclick="javascript:openPage('review.html?review='\''
+$title+'\')" />
Is there alternative way or am i not doing it right?
Here is a working example how to do this:
This transformation:
when applied on this XML document (no XML document was provided!):
produces the wanted, correct result:
Explanation: Use of AVT (Attribute Value Templates).
It is also possible to access xsl variable from a JavaScript code in the same file by doing the following:
<xsl:variable name="title" select="TITLE"/>
You forgot about {}: