我的xml看起来像
<details>
<addr>
<streetAddressLine>90822 abc lane</streetAddressLine>
<streetAddressLine>apt b</streetAddressLine>
<!-- streetAddressLine element is repeatable -->
<state>xyz</state>
</addr>
</details>
我正在寻找xpath表达式,它可以给我字符串长度(streetAddressLine [0])+字符串长度(streetAddressLine [1])+ ..... +字符串长度(streetAddressLine [n] )
答案 0 :(得分:1)
string-length(string-join(/details/addr/streetAddressLine/text(),""))
答案 1 :(得分:1)
现在我们知道你想要一个XPath 2.0解决方案,这个表达式:
sum(/details/addr/streetAddressLine/string-length())
结果:
19
对于XSLT 1.0解决方案,此样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="vStreetAddressLines">
<xsl:copy-of select="/details/addr/streetAddressLine"/>
</xsl:variable>
<xsl:value-of select="string-length($vStreetAddressLines)"/>
</xsl:template>
</xsl:stylesheet>
输出:
19