user1567386
user1567386

Reputation: 11

Count number of commas using xpath

I am trying to write an xpath expression to count the number of commas in an element. Is it possible to do that? If yes, then could someone help me with the expression. I need to count the commas from the node.

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

Thanks in advance.

Upvotes: 1

Views: 268

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

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, ',', '')

Upvotes: 1

Related Questions