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>

Drag a Scripting functoid onto the BizTalk Mapper. Go to properties and choose Configure functoid script. Choose Inline XSLT Call Template as the Script Type. Paste the above code in the Script Buffer text area. This functoid will take the comma separated string in as the first parameter and the destination element name as the second parameter. It will split the string into parts and create a sequence of elements in the destination message.

Observe the use of recursion (marked in bold), to solve similar problems. Have any questions, post a comment.


Comments

Saravana said…
This comment has been removed by a blog administrator.
Devdutt said…
Ram, i can help, if u leave ur contact details.
Saravana said…
Dev
Thanks for your reply.Can you mail me your contact details at gnsrk@yahoo.com
Thanks
Ramkumar
Anonymous said…
Hello Dev,

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
Devdutt said…
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

Popular posts from this blog

Sending Messages as FORM Variables with the HTTP Adapter

Uniform Sequential Convoys in BTS 2004 using Correlation