xml XSL - 如何禁用属性的输出转义?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2921123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:07:24  来源:igfitidea点击:

XSL - How to disable output escaping for an attribute?

xmlsharepointxsltsharepoint-designer

提问by Kobi

I've had the following <a>tag:

我有以下<a>标签:

<a href="http://myserver/_forms?url={@FileRef}&amp;id=5">...</a>

One of the files is called "File's got apostrophe.xml". The output of the XSL is:

其中一个文件名为"File's got apostrophe.xml". XSL 的输出是:

<a href="http://myserver/_forms?url=/blah/File&amp;#39;s got apostrophe.xml&id=5">...</a>

The problem is that the apostrophe is HTML-escaped (twice?) into &amp;#39;, which breaks the link.

问题是撇号是 HTML 转义的(两次?)&amp;#39;,这会破坏链接。

I've also tried using <xsl:attribute>, with same results:

我也试过使用<xsl:attribute>,结果相同:

<a>
  <xsl:attribute name="href">
    <xsl:value-of select="concat('http://myserver/_forms?url=', @FileRef, '&amp;id=5')"
         disable-output-escaping="yes" />
  </xsl:attribute>
</a>

Outputting <xsl:value-of select="@FileRef" disable-output-escaping="yes" />works well - the unescaped value is printed on the page.

输出<xsl:value-of select="@FileRef" disable-output-escaping="yes" />效果很好 - 未转义的值打印在页面上。

How can I set the attribute without escaping the string?

如何在不转义字符串的情况下设置属性?

回答by tpeczek

You can generate your <a> as text:

您可以将 <a> 生成为文本:

<xsl:text disable-output-escaping="yes">&lt;a href="</xsl:text>
<xsl:value-of select="concat('http://myserver/_forms?url=', @FileRef, '&amp;id=5')" disable-output-escaping="yes" />
<xsl:text disable-output-escaping="yes">" &gt;/a&lt;</xsl:text>

回答by Stephen Rushing

I know I'm a bit late on this, but I think the attribute tag is the way to, you just don't want to concat...

我知道我在这方面有点晚了,但我认为属性标签是方法,你只是不想连接......

<a>
  <xsl:attribute name="href">
    http://myserver/_forms?url=<xsl:value-of select="@FileRef" disable-output-escaping="yes" />&amp;id=5
  </xsl:attribute>
</a>