【发布时间】:2017-07-27 16:59:32
【问题描述】:
我正在寻找一些提示,获取Cdata元素的字符串长度
<root>
<description><![CDATA[This handbook covers the major topics <b>in</b> Spanish, but is by no means complete.]]></description>
</root>
我所尝试的,我正在使用 XSLT 1.0
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:variable name="Values">
<xsl:value-of select="root/description" disable-output-escaping="yes"/>
</xsl:variable>
<xsl:value-of select="string-length($Values)"/>
</xsl:stylesheet>
总字符串长度为 85 它包括 <b></b>,但我需要 79 除了 <b></b>。
请让我有一些想法。
【问题讨论】:
-
disable-output-escaping在变量中不起作用,这就是为什么你没有得到你想要的结果。在没有扩展函数的 XSLT 1.0 或 2.0 中,没有简单的方法可以解决这个问题。 -
如果您想将
<b></b>视为标记,那么您到底为什么要将它放在CDATA 部分? CDATA 的意思是“将此处的所有内容视为文本,即使它看起来像标记”。这就是 CDATA 的用途,也是它唯一的用途。