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 string into an embedded flash file.
I am having trouble getting an &
symbol to show up in XSLT. If I just type &
with no tags around it, there is a problem rendering the XSLT document. If I type &
with no tags around it, then the output of the document is &
with no change. If I type <xsl:value-of select="&" />
or <xsl:value-of select="&" />
I also get an error. Is this possible? Note: I have also tried &amp;
with no success.
If your transform is emitting an XML document, you shouldn't disable output escaping. You want markup characters to be escaped in the output, so that you don't emit malformed XML. The XML object that you're processing the output with (e.g. a DOM) will unescape the text for you.
If you're using string manipulation instead of an XML object to process the output, you have a problem. But the problem's not with your XSLT, it's with the decision to use string manipulation to process XML, which is almost invariably a bad one.
If your transform is emitting HTML or text (and you've set the output type on the
<xsl:output>
element, right?), it's a different story. Then it's appropriate to usedisable-output-escaping='yes'
on your<xsl:value-of>
element.But in any case, you'll need to escape the markup characters in your XSLT's text nodes, unless you've wrapped the text in a CDATA section.
org.apache.xalan.xslt.Process, version 2.7.2 outputs to the "Here is a runnable, short and complete demo how to produce such URL" mentioned above:
The XML declaration is suppressed with an additional
omit-xml-declaration="yes"
, but however with outputmethod="text"
escaping the ampersands is not justifiable.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 totext
by including the following as a child of thexsl:stylesheet
This will prevent the stylesheet from escaping things and
<xsl:value-of select="'&'" />
should produce&
.Use
disable-output-escaping="yes"
in yourvalue-of
tagUsing 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
try: <xsl:value-of select="&" disable-output-escaping="yes"/>
Sorry if the formatting is messed up.