如何从XSLT输出&符号 [英] How to output ampersand (&) from 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"/>
现在,在您的特定情况下,您说文本框中的&
被显示为"&
".我完全看不到.除了上面展示了如何生成&
而不是&
的XML或XSLT之外,HTML本身对于&
...
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 &
...
考虑以下简单的测试HTML:
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 &
.
这篇关于如何从XSLT输出&符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!