CountOccurrences
Originally contributed by Matt Bramer (@IOnline247) and adapted by Marc D Anderson (@sympmarc).
This template count the number of occurrences of findString
within the
withinString
using recursive calls.
<xsl:call-template name="CountOccurrences"> <xsl:with-param name="withinString" select="@Title" /> <xsl:with-param name="findString" select="'A'" /> </xsl:call-template>
<xsl:template name="CountOccurrences"> <xsl:param name="withinString" /> <xsl:param name="findString" /> <xsl:param name="counter" select="0" /> <xsl:choose> <xsl:when test="contains($withinString, $findString)"> <xsl:call-template name="CountOccurrences"> <xsl:with-param name="withinString" select="substring-after($withinString, $findString)" /> <xsl:with-param name="findString" select="$findString" /> <xsl:with-param name="counter" select="$counter + 1" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$counter" /> </xsl:otherwise> </xsl:choose> </xsl:template>