View Single Post
  #1 (permalink)  
Old July 6th, 2009, 07:38 AM
chandra_perni chandra_perni is offline
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2009
Posts: 13
Thanks: 6
Thanked 0 Times in 0 Posts
Default Incrementing a variable in XSL

Input XML:
-----------
<OUT>
<OUT_ITEM>
<ITEM_ID>151844</ITEM_ID>
</OUT_ITEM>
<OUT_ITEM>
<ITEM_ID>151845</ITEM_ID>
</OUT_ITEM>
<OUT_ITEM>
<ITEM_ID>151846</ITEM_ID>
</OUT_ITEM>
</OUT>

Expected Output:
----------------
<?xml version = '1.0' encoding = 'UTF-8'?>
<ILResponse>
<DA>
<Revision>
<Number>1</Number>
</Revision>
</DA>
<DA>
<Revision>
<Number>2</Number>
</Revision>
</DA>
<DA>
<Revision>
<Number>3</Number>
</Revision>
</DA>
</ILResponse>

XSL tried code:
---------------
<xsl:template match="/">
<ILResponse>
<xsl:for-each select="OUT/OUT_ITEM">
<DA>
<xsl:variable name="ItemIndex" select="0"/>
<xsl:variable name="ItemIndex1" select="$ItemIndex+1"/>
<Revision>
<Number>
<xsl:value-of select="$ItemIndex1"/>
</Number>
</Revision>
</DA>
</xsl:for-each>
</ILResponse>
</xsl:template>

I want to increment the variable for the no of times the OUT_ITEM are there in the input XML. My goal is to maintain the index value. please suggest. Found that every time the initial value of the variable is returned.
Reply With Quote