Search

Hi guys, hope for your help. How can I use xsl value:

<xsl:value-of select="/data/player/title" /> 

in jquery code (audio.js):

var title = '<xsl:value-of select="/data/player/title" />';

  markup: '
        <div class="controls"> 
            <div class="download"></div> 
            <div class="play-pause"> 
                <p class="play"></p> 
                <p class="pause"></p> 
                <p class="error"></p> 
            </div> 
        </div>  
        <div class="title"> ' +title+ ' </div>
        <div class="scrubber"> 
                <div class="progress"></div> 
                <div class="loaded"></div> 
        </div>'

Now i see a plain text.

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[&lt;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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details