Biztalk Mapping-XSLT Template
Hi,

I need to call a template inside a template(as it had a loop inside a loop) so I am using two templates one inside another. When I do this I was not able to access [$index1] values in  <xsl:template name="LoopableAddress"> and if I give <xsl:param name="index1"> this in LoopableAddress then Nothing was coming out in the destination.
  How can i access   [$index1] in the other template as well?
  Below are my two sample templates.

Template 1:

  <xsl:template name="LoopableData">
  <xsl:param name="index1" select="1" />
  <xsl:param name="total1" select="6" />
  <xsl:element name="ns0:NAME_DATA">
    <xsl:element name ="ns0:NAME">
      <xsl:value-of select="//TransactionRequest/RecData/Data[$index1]/Name/text()"/>
    </xsl:element>
    <xsl:element name ="ns0:ADDRESS">
      <xsl:call-template name="LoopableAddress"></xsl:call-template>
    </xsl:element>
  </xsl:element>
  <xsl:if test="not($index1 = $total1)">

    <xsl:call-template name="LoopablePolData">
      <xsl:with-param name="index1" select="$index1 + 1" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

Template 2:

<xsl:template name="LoopableAddress">

<xsl:param name="index1" select="1" /> {it is always pointing to the first record values as it is creating a new param}

<xsl:param name="index" select="1" />

  <xsl:param name="total" select="15" />
  <xsl:element name="ns0:ADDRESS">
    <xsl:element name ="ns0:ADDRESS1">
      <xsl:value-of select="//TransactionRequest/RecData/Data[$index1]/Add[$index]/Address1/text()"/>
    </xsl:element>
    <xsl:element name ="ns0:ADDRESS2">
      <xsl:value-of select="//TransactionRequest/RecData/Data[$index1]/Add[$index]/Address2/text()"/>
    </xsl:element>
  </xsl:element>
  <xsl:if test="not($index = $total)">
    <xsl:call-template name="LoopableAddress">
      <xsl:with-param name="index" select="$index + 1" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

July 2nd, 2013 9:21am

Hi,

You could add an extra param to the second template which holds this index, and in the call template in your first template you supply the appropriate value.

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 9:33am

Thanks for your response

Could you please elaborate....

How can I add and extra param in the second template that holds the value of the first tem

July 2nd, 2013 9:41am

Ah, you already had the extra parameter in your second template, you only do not provide a proper value to it, when you use it:

In your first template add the bold part:

<xsl:element name ="ns0:ADDRESS">
      <xsl:call-template name="LoopableAddress">
           <xsl:with-param name="index1" select="$index1" />
      </xsl:call-template>
</xsl:element>

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 9:45am

Thanks for your response Rene. It worked for me
July 2nd, 2013 10:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics