I am trying to use an xsl variable in a javascript block in my xslt file and I am at my wit's end.
Here is the XSLT (edited for public consumption):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="a">
<xsl:variable name="myVar" select="xpath to the node"/>
<script type='text/javascript'>
googletag.cmd.push(function() {
...
googletag.pubads().setTargeting('label', '<xsl:value-of select="$myVar"/>');
googletag.enableServices();
});
</script>
</xsl:template>
</xsl:stylesheet>
If I transform the XML in Oxygen, this code works fine. But when I run it through my servlet, which uses javax.xml.transform.Transformer.transform(Source xmlSource, Result outputTarget) throws TransformerException, I get this:
googletag.pubads().setTargeting('label', ' ');
Can anyone suggest a possible reason for this discrepancy between Oxygen and my servlet?
$myVarand when run through the servlet there is no value for value-of? It could be a difference between what docs are sent to the transforms. What is the xpath to the node? Are you sure that it is matching? Reduce to a more simple test of just an XSLT that produces the value of the$myVarto verify that you are correctly matching when run through the servlet.