New template: NumOfOccurrences

Jul 21, 2011 at 1:11 PM
Edited Jul 21, 2011 at 1:12 PM

I found this to be useful working today on some tricky string manipulations.

Template Usage:

<xsl:call-template name="NumOfOccurences">
	<xsl:with-param name="withinString" select="@PersonnelFullName" />
	<xsl:with-param name="findString" select="'-'" />
</xsl:call-template>

Template:

<xsl:template name="NumOfOccurences">
		<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="NumOfOccurences">
					<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>
Coordinator
Jul 21, 2011 at 1:15 PM

Nice, Matt. I'll test it and add it to the project!

M.