[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] conditional increment under XSL for-each loop


Subject: RE: [xsl] conditional increment under XSL for-each loop
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 9 Feb 2010 15:02:39 -0000

> I have a requirment which should show the xml o/p like below
> 
> <instance>
> <mezo eazon="001X1A">abc</mezo>
> <mezo eazon="001X2A">def</mezo>
> <mezo eazon="002X1A">xyz</mezo>
> <mezo eazon="002X2A">abc</mezo>
> <mezo eazon="003X1A">def</mezo>
> <mezo eazon="003X2A">xyz</mezo>
> <mezo eazon="004X1A">aaa</mezo>
> <mezo eazon="004X2A">bbb</mezo>
> <mezo eazon="005X1A">ccc</mezo>
> <mezo eazon="005X2A">xyz</mezo>
> </instance>
> 
> 
> The tag "001X1A"  should frame in such a way that,
> POINT1 : The number appearing before 'A' should reset after 
> every two records
> POINT2 : The number appearing before 'X' should be same and 
> need to increment by 1 for every two records.
> like 001,001 then 002,002 then 003....
> 
> 
> Is this possible to get through the XSL

Yes, but not if you think about it procedurally the way you are doing. You
need to think how the output value can be computed as a function of the
input. Try something like:

<xsl:for-each select="G_REP_TRX_DETAIL_INFO/C_TAX_REPORTING_NAME">
  <mezo eazon="{format-number((position()+1) idiv 2,
'000')}X{((position()+1) mod 2) + 1}A">
    <xsl:value-of select="."/>
  </mezo>
</xsl:for-each>

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> 
> KIindly advice
> 
> iam providing my xml file also
> <ZXXEUSL>
>   <LIST_G_REP_PARAMETER_INFO>
>     <G_REP_PARAMETER_INFO>
>       <CP_ESL_ROUND_RULE_CODE>NO</CP_ESL_ROUND_RULE_CODE>
>     </G_REP_PARAMETER_INFO>
>   </LIST_G_REP_PARAMETER_INFO>
>   <LIST_G_REP_TRX_DETAIL_INFO>
>     <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>abc</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>     <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>def</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>      <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>xyz</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>      <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>abc</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>      <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>def</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>      <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>xyz</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>      <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>aaa</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>       <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>bbb</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>        <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>ccc</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>        <G_REP_TRX_DETAIL_INFO>
>       <C_TAX_REPORTING_NAME>xyz</C_TAX_REPORTING_NAME>
>     </G_REP_TRX_DETAIL_INFO>
>  </LIST_G_REP_TRX_DETAIL_INFO>
>   <CS_CURRENCY_CODE>GBP</CS_CURRENCY_CODE>
> </ZXXEUSL>
>  
>  
> Thanks
> Anil


Current Thread
Keywords