问题描述
我对 xslt、js 和 html 实体有一个小问题,例如.在模板中:
i have a tiny little problem with xslt, js and html entities, eg. within a template:
<script type="text/javascript">
<xsl:value-of select="/some/node"/>
for (var i = 0; i < 5; i++) {
// ^^^ js error
}
</script>
<script type="text/javascript">
<xsl:value-of select="/some/node"/>
for (var i = 0; i < 5; i++) {
// ^ xslt error
}
</script>
<script type="text/javascript">
<xsl:value-of select="/some/node"/>
// <![CDATA[
for (var i = 0; i < 5; i++) {
// ^ becomes <
}
// ]]>
</script>
<script type="text/javascript">
<xsl:value-of select="/some/node"/>
for (var i = 0; i <xsl:value-of disable-output-escaping="yes" select="string('<')"/> 5; i++) {
// works of course
}
</script>
有谁知道我的问题可能来自哪里?我一直认为 xslt 处理器会留下 <script/> 的内容.使用 html 输出方法时未转义的元素 ...
does anyone have an idea where my problem could come from? i always thought the xslt processor would leave the content of a <script/> element unescaped when using the html output method ...
我在使用 macportsports 安装的 OSX 上运行 libxslt2 版本 1.1.24 ...
i run libxslt2 version 1.1.24 on OSX which was installed using macportsports ...
推荐答案
ok.长话短说:
似乎在某些 libxslt 版本中,xslt 处理器在使用 html 输出方法时将 <script/> 元素的内容保留为未转义,对于其他版本不是 ...因此建议如下:
it seems that with some libxslt versions the xslt processor leaves the content of a <script/> element unescaped when using the html output method, with othersnot ... therefore the following is recommended:
<script type="text/javascript">
<xsl:value-of select="/some/node"/>
<xsl:text disable-output-escaping="yes">
// ^ does the trick ...
for (var i = 0; i < 5; i++) {
// ^ works
}
</xsl:text>
</script>
这篇关于xslt、javascript 和未转义的 html 实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!