如何从XSLT输出&符号 [英] How to output ampersand (&) from XSLT

查看:98
本文介绍了如何从XSLT输出&符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将XML中的所有&转换为&,以便XSLT可以编译.我正在将XML样式化为HTML.但是,当文本框由XSLT填充时,我需要&才能显示为&.

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 &.

例如,它在文本框中显示"you & me",但是我需要看到"you & me".

For example, it shows "you & me" in the text box, but I need to see "you & me".

推荐答案

如何在XSLT中将&输出为&

通常,这是将&输出为&的替代技术:

How to output & as & in XSLT

In general, here are alternative techniques for outputting & as &:

  • 全局:

  • Globally:

<xsl:output method="html"/>
or
<xsl:output method="text"/>`

  • 对于源自XSLT的&"号:

  • For ampersands originating from XSLT:

    <xsl:text disable-output-escaping="yes"><![CDATA[&]]></xsl:text>
    

  • 对于源自输入XML的&符号:

  • For ampersands originating from input XML:

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

  • 现在,在您的特定情况下,您说文本框中的&amp;被显示为"&amp;".我完全看不到.除了上面展示了如何生成&而不是&amp;的XML或XSLT之外,HTML本身对于&amp; ...

    Now, in your specific case you say that &amp;s within text boxes are being displayed as "&amp;". I don't see that at all. Apart from XML or XSLT, in which I show above how to generate & rather than &amp;, HTML itself really has no problem with &amp;...

    考虑以下简单的测试HTML:

    Consider this simple test HTML:

    <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 renders in browsers as follows:

    如您所见,将&amp;呈现为&毫无问题.

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

    这篇关于如何从XSLT输出&符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆