Setting an XSLT variable as a JavaScript variable?

2019-08-13 22:29发布

问题:

How would I grab an XSLT variable and use it to set a JavaScript variable?

I'm working on a bit of AJAX and in order to make it work to the fullest I would like to be able to grab XSLT variables and use those to set the default values of some JavaScript variables that I'll then be manipulating with jQuery.

回答1:

Stick something like the following in your XSLT part that outputs the JavaScript.

<xsl:variable name="myvar" select="'red'" />
<xsl:text>var myobj="</xsl:text><xsl:value-of select="$myvar"></xsl:value-of><xsl:text>"</xsl:text>