I have an XML which is describe below. This xml contains for example address node(address1). I just want to count the number of occurrence of character(,) in the address text. I am using template so just to mention I an storing address text into xslt variable.
Sample XML:
<xml>
<address1>123 Fake Street, Alberta, Alberta, 234567</address1>
<address1>123 Fake Street, Alberta, Alberta</address1>
</xml>
My XSLT:
<xsl:variable name="address" select="//*[local-name()='address1')]"/>
<xsl:variable name="totalComma" select="count(contains($address, ','))"/>
<xsl:choose>
<xsl:when test="$totalComma = 3">
<!--Do something-->
</xsl:when>
<xsl:when test="$totalComma = 2">
<!--Do something-->
</xsl:when>
</xsl:choose>
I don't know whether this is correct solution or not but didn't get expected result. A little help would be highly appreciable.
Use string-length(foo) - string-length(translate(foo, ',', ''))
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With