Sorting with the BizTalk Mapper part II (Multi-Level Sort XSLT)

By patrickwellink
December 8, 2005
Comments Off on Sorting with the BizTalk Mapper part II (Multi-Level Sort XSLT)

As I explained in a previous post (see here) it is possible to sort nodes with the BizTalk mapper. However the example in that post is only one level deep and we have to sort that level. What if there are multiple levels and we need to sort every level. Wel the trick is you have to use a For-Each for every repeating node. Besides that you will have to create the nodes yourself in the scripting functoid. Below is a sample of a script I used to sort multiple levels in the BizTalk mapper.

<xsl:for-each select="ns0:Level3/ns0:Level4">
   <Level4 xmlns="
http://www.BizTalkSamples/multilevelsort">
   <xsl:for-each select="ns0:Level5">
      <xsl:sort select="ns0:ID" data-type="text" order="ascending"/>
      <Level5>
      <xsl:copy-of select="ns0:ID"/>
      <xsl:copy-of select="ns0:Node1"/>
      <xsl:copy-of select="ns0:Node2"/>
      <xsl:copy-of select="ns0:Node3"/>
      <xsl:copy-of select="ns0:Node4"/>
      <xsl:copy-of select="ns0:etc."/>
      <xsl:copy-of select="ns0:etc."/>
      <xsl:for-each select="ns0:Level6">
        <xsl:sort select="ns0:ID" data-type="text" order="ascending"/>
        <Level6>
        <xsl:copy-of select="ns0:ID"/>
        <xsl:copy-of select="ns0:Node1"/>
        <xsl:copy-of select="ns0:Node2"/>
        <xsl:copy-of select="ns0:Node3"/>
        <xsl:copy-of select="ns0:Node4"/>
        <xsl:copy-of select="ns0:etc."/>
        <xsl:copy-of select="ns0:etc."/>
        </Level6>
     </xsl:for-each>
     </Level5>
     </xsl:for-each>
   </Level4>
</xsl:for-each>

In the previous post I could do with a copy of Select = "." to select the current node and all its childeren. With a multilevel sort however, this will not work, cause selecting "."  will select the (unsorted) childeren. I am quite new to XSLT and I couldn’t find a good example of a XSLT multi-level sort on the internet. Hope this sample will help somebody…

 

Comments: 0

Comments are closed.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta