How to output ampersand (&) from XSLT

I am converting everything &

to &

my XML in order to compile the XSLT. I am styling XML to HTML. However, when the textbox is filled with XSLT, I need it to &

appear as &

.

For example, the text box displays " you & me

", but I need to see " you & me

".

+3


source to share


2 answers


How to output &

as &

in XSLT

In general, here are the alternative output methods &

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 coming from input XML:

    <xsl:value-of select="XPATH EXPRESSION" disable-output-escaping="yes"/>
    
          


Now, in your specific case, you say what &amp;

appears in the text boxes as " &amp;

". I don't see that. Apart from XML or XSLT, in which I show above how to generate &

rather than &amp;

, HTML itself really has no problem with &amp;

...



Consider this simple HTML test:

<html>
  <body>
    <h3>No &amp;amp; is displayed in any of these cases:</h3>
    <div>
      In an input box:
      <input type="text" value="Ampersand: &amp;"/>
    </div>
    <div>
      In a text area:
      <textarea>Ampersand: &amp;</textarea>
    </div>
    <div>In a div: Ampersand: &amp;</div>
  </body>
</html>

      

This is displayed in browsers like this:

enter image description here

As you can see, there is no problem with rendering &amp;

like &

.

+6


source


&#38;

Will work very well in many situations . It is valid xml, understandable also by the browser. XSL, someone else loves youuuuuuuuuu.



0


source







All Articles