I'm converting all &
into &
in my XML so that the XSLT will compile. I'm styling the XML into HTML. However when a textbox is populated by the XSLT, I need the &
to display as &
.
For example, it shows "you & me
" in the text box, but I need to see "you & me
".
Use & in place of & .
It's very easy. Just extend the range of your translate() call to cover the problem characters (characters that you use in the attribute, but that XML forbids for element names).
&
as &
in XSLTIn general, here are alternative techniques for outputting &
as &
:
Globally:
<xsl:output method="html"/>
or
<xsl:output method="text"/>`
For ampersands originating from XSLT:
<xsl:text disable-output-escaping="yes"><![CDATA[&]]></xsl:text>
For ampersands originating from input XML:
<xsl:value-of select="XPATH EXPRESSION" disable-output-escaping="yes"/>
Now, in your specific case you say that &
s within text boxes are being displayed as "&
". I don't see that at all. Apart from XML or XSLT, in which I show above how to generate &
rather than &
, HTML itself really has no problem with &
...
Consider this simple test HTML:
<html>
<body>
<h3>No &amp; is displayed in any of these cases:</h3>
<div>
In an input box:
<input type="text" value="Ampersand: &"/>
</div>
<div>
In a text area:
<textarea>Ampersand: &</textarea>
</div>
<div>In a div: Ampersand: &</div>
</body>
</html>
This renders in browsers as follows:
As you can see, there is no problem rendering &
as &
.
In many situations &
will work very well. It's valid xml, understood also by the browser. XSL, some-one-still-loves-youuuuuuuuu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With