禁用输出转义不适用于xslt中的属性 [英] Disable output escaping not working for attribute in xslt

查看:46
本文介绍了禁用输出转义不适用于xslt中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下xml-node:

I have the following xml-node :

<name>P &amp; P</name>

并遵循XSL

<a href="example.htm" >

    <xsl:attribute name="title">
       <xsl:value-of select="name" disable-output-escaping="yes"></xsl:value-of>
    </xsl:attribute>    


     <xsl:value-of select="name" disable-output-escaping="yes"></xsl:value-of>
</a>

可以编译为此HTML

That compiles to this HTML

<a href="example.com" title="P &amp;amp; P">
  P &amp; P
</a>

因此非转义适用于值(<A></A>之间的文本),而不适用于属性.

So the non-escaping worked for the value (the text between <A></A>) but not for the attribute.

我在这里想念东西吗?

谢谢!

推荐答案

摘自OP的评论:

我在HTML标签的title属性中需要这个xml(P& P).一种 更好的解决方案是最欢迎的!

I need this xml (P & P) in the title attribute of an HTML tag. A better solution is most welcome!

无需D-O-E即可完美完成您需要生成的内容.

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/*">
     <a href="example.htm" title="{.}">
       <xsl:value-of select="."/>
     </a>
 </xsl:template>
</xsl:stylesheet>

应用于以下XML文档:

<t>P &amp; P</t>

产生想要的正确结果:

<a href="example.htm" title="P &amp; P">P &amp; P</a>

这篇关于禁用输出转义不适用于xslt中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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