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.
1 <xsl:template name="TokenizeCommaSepString">
2 <xsl:param name="stringToTokenize" />
3 <xsl:param name="destinationElementName" />
4 <xsl:if test="$stringToTokenize != ''">
5 <xsl:choose>
6 <xsl:when test="contains($stringToTokenize, ',')=0">
7 <xsl:element name="{$destinationElementName}">
8 <xsl:value-of select="$stringToTokenize" />
9 </xsl:element>
10 </xsl:when>
11 <xsl:otherwise>
12 <xsl:element name="{$destinationElementName}">
13 <xsl:value-of select="substring-before($stringToTokenize, ',')" />
14 </xsl:element>
15 </xsl:otherwise>
16 </xsl:choose>
17 <xsl:call-template name="TokenizeCommaSepString">
18 <xsl:with-param name="stringToTokenize" select="substring-after($stringToTokenize,',')" />
19 <xsl:with-param name="destinationElementName" select="$destinationElementName" />
20 </xsl:call-template>
21 </xsl:if>
22 </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.