1

我正在尝试编写一个 xpath 表达式来计算元素中逗号的数量。有可能这样做吗?如果是的话,那么有人可以帮我表达一下。我需要计算节点中的逗号。

<SOISWPUpload>
  <User>admin</User>
  <SWPIdentifiers>,,,,,U,,,SWP,20120630,,,,4113,,COAC,TLMCOAC
,,,,,U,,,SWP,20120630,,,,4113,,COAC,TLMCOAC</SWPIdentifiers>
</SOISWPUpload>

提前致谢。

4

1 回答 1

1

Use:

string-length() - string-length(translate(., ',', '')

In this concrete case you may want to specify the context-node:

string-length(/*/SWPIdentifiers) - string-length(translate(/*/SWPIdentifiers, ',', '')
于 2012-08-01T04:16:24.877 回答