I am trying to create a query string of variable assignments separated by the &
symbol (ex: \"var1=x&var2=y&...\"
). I plan to pass this
If you are trying to produce an XML file as output, you will want to produce &
(as &
on it's own is invalid XML). If you are just producing a string then you should set the output mode of the stylesheet to text
by including the following as a child of the xsl:stylesheet
<xsl:output method="text"/>
This will prevent the stylesheet from escaping things and <xsl:value-of select="'&'" />
should produce &
.
You can combine disable-output-escaping
with a CDATA
section. Try this:
<xsl:text disable-output-escaping="yes"><![CDATA[&]]></xsl:text>
Just replace & with
<![CDATA[&]]>
in the data. EX: Data XML
<title>Empire <![CDATA[&]]> Burlesque</title>
XSLT tag:
<xsl:value-of select="title" />
Output: Empire & Burlesque
Use disable-output-escaping="yes"
in your value-of
tag
You should note, that you can use disable-output-escaping within the value of node or string/text like:
<xsl:value-of select="/node/here" disable-output-escaping="yes" />
or
<xsl:value-of select="'&'" disable-output-escaping="yes" />
<xsl:text disable-output-escaping="yes">Texas A&M</xsl:text>
Note the single quotes in the xsl:value-of.
However you cannot use disable-output-escaping on attributes. I know it's completely messed up but, that's the way things are in XSLT 1.0. So the following will NOT work:
<xsl:value-of select="/node/here/@ttribute" disable-output-escaping="yes" />
Because in the fine print is the quote:
Thus, it is an error to disable output escaping for an
<xsl:value-of />
or<xsl:text />
element that is used to generate the string-value of a comment, processing instruction or attribute node;
emphasis mine.
Taken from: http://www.w3.org/TR/xslt#disable-output-escaping
Using the disable-output-escaping
attribute (a boolean) is probably the easiest way of accomplishing this. Notice that you can use this not only on <xsl:value-of/>
but also with <xsl:text>
, which might be cleaner, depending on your specific case.
Here's the relevant part of the specification: http://www.w3.org/TR/xslt#disable-output-escaping