Geeks With Blogs
Devdutt's Blog My ramblings on just about everything...

Yet another very old post from my previous blog.

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.

Posted on Friday, August 12, 2005 10:23 AM BizTalk Server 2004 | Back to top


Comments on this post: Using recursion in the In-line XSLT Template type Scripting Functoid...

# re: Using recursion in the In-line XSLT Template type Scripting Functoid...
Requesting Gravatar...
Thank you very much for the example. I think it's the first time I see something coming out of an Inline XSLT Call Template in my map ;)

But I have a problem with my version of your XSLT: it just generates 1 output node when it should generate more :( Any idea?

Thank you again !!
Left by Paula on Aug 19, 2005 4:19 AM

# re: Using recursion in the In-line XSLT Template type Scripting Functoid...
Requesting Gravatar...
If you pass an input string like:

red,blue,green,yellow

and the destination Elelment Name thats passed is "Color":

then your resultant xml should look like
<Color>red</Color>
<Color>blue</Color>
<Color>green</Color>
<Color>yellow</Color>
Left by Dev on Aug 19, 2005 10:22 AM

# re: Using recursion in the In-line XSLT Template type Scripting Functoid...
Requesting Gravatar...
Thank you for your reply.

Now it works. It was a problem with a looping functoid in a second transformation :)
Left by Paula on Aug 22, 2005 1:15 AM

# re: Using recursion in the In-line XSLT Template type Scripting Functoid...
Requesting Gravatar...
Sure thing, I'd hoped someone eventually would. :)
Left by dev on Feb 01, 2006 8:14 PM

# re: Using recursion in the In-line XSLT Template type Scripting Functoid...
Requesting Gravatar...
Hi
I am not able to use this example can you please send me an example for using this functiod

Left by Simit on Jun 20, 2006 10:08 PM

# re: Using recursion in the In-line XSLT Template type Scripting Functoid...
Requesting Gravatar...
Hi,

i have nearly the same problem - i must split a large text field into portions of 80 characters.

i'm an absolut newbie on xslt - so please can you help me ?

thx,
Markus
Left by Markus on Jun 21, 2006 9:21 AM

Your comment:
 (will show your gravatar)


Copyright © Devdutt Patnaik | Powered by: GeeksWithBlogs.net