简体   繁体   中英

Counting the occurrences of a character in a string

In XSLT 1.0, I have a node with values having special characters, numbers, alphabets. From this , I need to take the count of a particular character. Consider the below node.

<sample>abc.123.@#$,def$%^123.kl.lo</sample>

In this, I need to get the count of decimal points alone. So, the result should be 4. Please put your thoughts. Below are few codes that I tried.

<xsl:value-of select="count(/*/*/sample[contains(., '.')]) "/>

<xsl:value-of select="count(//sample[.])"/>

检查此代码即可解决问题

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM