![](/img/trans.png)
[英]how to transform xml with xslt preserving <br /> and not preserve other tags in a text
[英]How to remove <br> tags and leave all other tags using xslt
我正在尝试从xslt1.0中的字符串中删除break标记。 我尝试使用translate(s,'&ltbr>',''),其中s是字符串值,但这也删除了粗体标签。 还尝试了一个模板,但没有运气。 我的问题是如何仅删除中断标签。
所以字符串:
<b>trying</b> to remove <br> tags only <br> and not <b>bold tags</b>
将被解析为:
<b>trying</b> to remove tags only and not <b>bold tags</b>
此XSLT:
<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="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"br[not(@*|*|comment()|processing-instruction())
and normalize-space()=''
]"/>
</xsl:stylesheet>
应用于格式正确,有效的XML:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<b>trying</b> to remove <br/> tags only <br/> and not <b>bold tags</b>
</list>
给出以下结果:
<list>
<b>trying</b> to remove tags only and not <b>bold tags</b>
</list>
另请参考Dimitre的解决方案: 通过XSLT从XML删除空标签
最好的问候,彼得
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.