title: How to use an xsl variable in a javascript block
body: <p>I am trying to use an xsl variable in a javascript block in my xslt file and I am at my wit's end. </p>
  
  <p>Here is the XSLT (edited for public consumption):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
  
      &lt;xsl:output method="html" indent="yes"/&gt;
      &lt;xsl:template match="a"&gt;
           &lt;xsl:variable name="myVar" select="xpath to the node"/&gt;
  
      &lt;script type='text/javascript'&gt;
  
              googletag.cmd.push(function() {
          ...
        googletag.pubads().setTargeting('label', '&lt;xsl:value-of select="$myVar"/&gt;');
              googletag.enableServices();
              });
  
    &lt;/script&gt; 
  
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>If I transform the XML in Oxygen, this code works fine.  But when I run it through my servlet, which uses  <code>javax.xml.transform.Transformer.transform(Source xmlSource, Result outputTarget) throws TransformerException</code>, I get this:
  <code>googletag.pubads().setTargeting('label', ' ');</code> </p>
  
  <p>Can anyone suggest a possible reason for this discrepancy between Oxygen and my servlet?  </p>