August 2010 - Posts

Using XSLT Templates in a map (reminder@self)

We all know that using XSLT inside a map can be very usefull to do stuff that's very hard to do with the mapper itself.
Sometimes using XSLT it is the only way things can be done. I find myself struggeling each time to figure out how specific tasks work with XSLT.

That's why I write this post. So I wont have to figure it all out again the next time i need this functionality....
Below is some code used in an 'Inline XSLT Call Template' to calculate the number of segments in a message (UNT) and the message Message Reference number.

The input CurrentIndex is retrieved from an Iteration functoid that returns the current index of the transaction. This index is used to retrieve the correct values for the UNT segment of that transaction
( I am using the batched EDI schema's).

<xsl:template name="UNTTemplate">

  <xsl:param name="currentIndex" />

  <xsl:variable name="sum01" select="count(/s2:Request/INTERCHANGE/UNB)" />

  <xsl:variable name="sum02" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/UNH)" />

  <xsl:variable name="sum03" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/BGM)" />

  <xsl:variable name="sum04" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/DTM)" />

  <xsl:variable name="sum05" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/NAD)" />

  <xsl:variable name="sum06" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN)" />

  <xsl:variable name="sum07" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/DTM)" />

  <xsl:variable name="sum08" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/NAD)" />

  <xsl:variable name="sum09" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/RFF)" />

  <xsl:variable name="sum10" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/QTY)" />

  <xsl:variable name="sum11" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/PRI)" />

  <xsl:variable name="sum12" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/IMD)" />

  <xsl:variable name="sum13" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/IMD/PRICE_INFORMATION)" />

  <xsl:variable name="sum14" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/PAC)" />

  <xsl:variable name="sum15" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/PAC/PRI)" />

  <xsl:variable name="sum16" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/EQD)" />

  <xsl:variable name="sum17" select="count(/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/LIN/EQD/EQN)" />

  <xsl:variable name="unt18"  select="/s2:Request/INTERCHANGE/TRANSACTION[position()=$currentIndex]/UNH/MESSAGE_REFERENCE_NUMBER" />

  <xsl:variable name="totalCount" select="$sum01 + $sum02 + $sum03 + $sum04 + $sum05+ $sum06 + $sum07 + $sum08 + $sum09 + $sum10 + $sum11 + $sum12 + $sum13 + $sum14 + $sum15+ $sum16 + $sum17" />

  <xsl:element name="UNT">

    <xsl:element name="UNT1">

      <xsl:value-of select="$totalCount" />

    </xsl:element>

    <xsl:element name="UNT2">

      <xsl:value-of  select="$unt18" />

    </xsl:element>

  </xsl:element>

</xsl:template>

 

Posted by Patrick Wellink with no comments
Filed under: , ,