我经常使用这个 xpathsum(preceding::*/string-length())
它完成了我需要它做的事情(在 XML 文件中提供直到此上下文的所有文本的字符数)。
问题:速度很慢。
我应该使用不同的内置函数吗?还是扩展?
更新:
根据 Michael Kay 的评论,我探索了 XSLT 3.0 <accumulator>
。这是我第一次尝试 3.0(我必须更新 OxygenXML 以使其工作)。我还没有完全适应我的需要,但下面的初步测试显示了希望。
<xsl:output method="xml" />
<xsl:accumulator
name="f:string-summ"
post-descent="f:accum-string-length"
as="xs:integer"
initial-value="0">
<xsl:accumulator-rule
match="text/*"
new-value="$value + string-length()"/>
</xsl:accumulator>
<xsl:template match="text/*">
<xsl:value-of select="f:accum-string-length()" />
</xsl:template>
题外话:Stack Overflow 需要一个“XSLT-3.0”标签。