XSL value in jQuery
This is an open discussion with 5 replies, filed under Troubleshooting.
Search
Are you trying to embed the "jquery" code in you xsl stylesheet? if so then you might wrap the codestring inside a CDATA section:
<![CDATA[<script> var title = ]]><xsl:value-of select="/data/player/title" /><![CDATA[; … //rest of your code]]>
You'd have to set the value in your XSLT style-sheet and not in the javascript file itself. As in the JS file no XSLT would work, then you can use the variable in your javascript without a problem. If its just a variable most of the time you do not need CDATA blocks.
ok, it works if js code in xslt file, but if it's script external i can't use this, no solutions?
ok, it works if js code in xslt file, but if it's script external i can't use this, no solutions?
If you want the value, but keep your JavaScript in an external file then you have several options if you think about it.
- use XSLT to generate the external JS file itself (don't bother with this, it's painful)
- write the value into your page as JavaScript variables/objects, as above, then load your JavaScript after this to read the value
- write the value into your page HTML (e.g. in
data
attributes) which JavaScript can then parse
write the value into your page HTML (e.g. in data attributes) which JavaScript can then parse
oh this is juicy. i'm glad i read this. thanks, nick!
Create an account or sign in to comment.
Hi guys, hope for your help. How can I use xsl value:
in jquery code (audio.js):
Now i see a plain text.