![](/img/trans.png)
[英]Sum String-Length of two different nodes with Xpath - Sum two nodes string-length
[英]XPath's string-length() of a node without its children
我需要一個單行 XPath 1.0 表達式來計算節點的長度,但不包括任何子節點中的文本(如果它們存在)。
例如,字符串長度()
<node>This is text</node>
是 12 (ok),但是 string-length() 的
<node>This is<any>any text</any> text</node>
<node>This <any>any text</any>is text</node>
大於 12(不行)。
我不能使用string-length(//node/text())
,因為它需要node
的第一個文本塊,如果node
有任何子node
。
單獨的 XPath 1.0 不能僅提供元素的文本節點子節點的字符數。 您還必須使用托管 XPath 庫的語言的工具。
這個 XPath(首先由@MartinHonnen 在評論中發布),
sum(/node/text()/string-length())
將根據要求提供/node
的所有文本節點子節點的字符數。
使用這個希望會為 1.0 運行:
string-length(//node)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.