I hope that you did not simplify the problem too much to ask about it, because it should not be a big problem.
You can define a template and call it recursively as long as you keep the input line format consistent.
For instance,
<xsl:template name="TrimMulti"> <xsl:param name="InputString"/> <xsl:variable name="RemainingString" select="substring-after($InputString,';#')"/> <xsl:choose> <xsl:when test="contains($RemainingString,';#')"> <xsl:value-of select="substring-before($RemainingString,';#')"/> <xsl:text>, </xsl:text> <xsl:call-template name="TrimMulti"> <xsl:with-param name="InputString" select="substring-after($RemainingString,';#')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$RemainingString"/> </xsl:otherwise> </xsl:choose> </xsl:template>
I checked this template with the following call:
<xsl:template match="/"> <xsl:call-template name="TrimMulti"> <xsl:with-param name="InputString">19;#John Smith;#17;#Ben Reynolds;#1;#Terry Jackson</xsl:with-param> </xsl:call-template> </xsl:template>
And I got the following conclusion:
John Smith, Ben Reynolds, Terry Jackson
It seems that you need to.
The explanation of what he does is easy to explain if you are familiar with functional programming. The InputString parameter is always in the form [number];#[name];#[rest of string] . Each call to the TrimMulti template TrimMulti [number];# part and imprints the [name] , and then passes the remaining expression to itself recursively.
In the base case, the InputString is in the form [number];#[name] , in which case the RemainingString variable will not contain ;# . Since we know that this is the end of the input, this time we do not output a comma.
source share