Using recursion in the In-line XSLT Template type Scripting Functoid
People using In-Line XSLT Templates in their scripting functoids often run into the need for looping, WITHOUT using an <xsl:for-each>. An example in the BizTalk context would be, if you had a comma separated string in the source schema and wanted to tokenize it into multiple destination schema elements. The following XSLT template does that for you.
<xsl:template name="TokenizeCommaSepString">
<xsl:param name="stringToTokenize" />
<xsl:param name="destinationElementName" />
<xsl:if test="$stringToTokenize != ''">
<xsl:choose>
<xsl:when test="contains($stringToTokenize, ',')=0">
<xsl:element name="{$destinationElementName}">
<xsl:value-of select="$stringToTokenize" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{$destinationElementName}">
<xsl:value-of select="substring-before($stringToTokenize, ',')" />
</xsl:element>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="TokenizeCommaSepString">
<xsl:with-param name="stringToTokenize" select="substring-after($stringToTokenize,',')" />
<xsl:with-param name="destinationElementName" select="$destinationElementName" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="TokenizeCommaSepString">
<xsl:param name="stringToTokenize" />
<xsl:param name="destinationElementName" />
<xsl:if test="$stringToTokenize != ''">
<xsl:choose>
<xsl:when test="contains($stringToTokenize, ',')=0">
<xsl:element name="{$destinationElementName}">
<xsl:value-of select="$stringToTokenize" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{$destinationElementName}">
<xsl:value-of select="substring-before($stringToTokenize, ',')" />
</xsl:element>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="TokenizeCommaSepString">
<xsl:with-param name="stringToTokenize" select="substring-after($stringToTokenize,',')" />
<xsl:with-param name="destinationElementName" select="$destinationElementName" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Comments
Thanks for your reply.Can you mail me your contact details at gnsrk@yahoo.com
Thanks
Ramkumar
I Just try to solve a problem in BizTalk2004 with the Mapper and I found your sample for recursion in XSLT, which unfortunately does not suite to my situation.
what I have:
Incoming:
GitemH
Gentity_propertyH
Gcontrol_idHBegin_TimeG/control_idH
Gprop_valuuH170000$090000$083000G/prop_valueH
G/entity_propertyH
Gentity_propertyH
Gcontrol_idHEnd_TimeG/control_idH
Gprop_valuuH190000$100000$123000G/prop_valueH
G/entity_propertyH
G/itemH
Outgoing:
GUserH
GBegin_TimeH170000G/Begin_TimeH
GEnd_TimeH190000G/End_TimeH
G/UserH
GUserH
GBegin_TimeH090000G/Begin_TimeH
GEnd_TimeH100000G/End_TimeH
G/UserH
GUserH
GBegin_TimeH083000G/Begin_TimeH
GEnd_TimeH123000G/End_TimeH
G/UserH
Any ideas how to solve this? Next to the recursion there must be a group, which I just don't know how to manage at this time... :-(
Best eregards
Patrick
sorry for the delay, i've been outta town. Will look into the problem and get back to you shortly. you can send replies to pyrogenic@hotmail.com.
Regards
Dev