Incrementing variable in xslt -


i have each loop , if condition under loop. want increment value of variable everytime if if condition true. based on value of variable i want implement logic. below code

<xsl:variable name="i" select="0"/> <xsl:for-each select="request/modifyproductsandpackages/nrclist/nrc"> <xsl:variable name="typeidnrcvar" select="typeidnrc"/>  <xsl:if test="count(/request/waivenrclist/waivenrc/typeidnrc[text()=$typeidnrcvar])=0">    <xsl:variable name="i" select="$i + 1"/>    <xsl:if test ="$i=1">        </xsl:if> </xsl:if> </xsl:for-each/> 

here value of not incremented. can please suggest how should accomplish above task. help.

below xml structure

<request> <modifyproductsandpackages> <nrclist>    <nrc>      <typeidnrc>14046</typeidnrc>      <serviceinternalid>98602440</serviceinternalid>      <serviceinternalidresets>0</serviceinternalidresets>      <viewableonly>1</viewableonly>    </nrc>    <nrc>      <typeidnrc>12002</typeidnrc>      <serviceinternalid>98602440</serviceinternalid>      <serviceinternalidresets>0</serviceinternalidresets>      <viewableonly>1</viewableonly>    </nrc>    <nrc>      <typeidnrc>13006</typeidnrc>      <serviceinternalid>98602440</serviceinternalid>      <serviceinternalidresets>0</serviceinternalidresets>      <viewableonly>1</viewableonly>    </nrc>    <nrc>      <typeidnrc>14098</typeidnrc>      <serviceinternalid>98602440</serviceinternalid>      <serviceinternalidresets>0</serviceinternalidresets>      <viewableonly>1</viewableonly>    </nrc>  </nrclist>       </modifyproductsandpackages> <waivenrclist> <waivenrc>   <typeidnrc>12002</typeidnrc>   <serviceinternalid>98602440</serviceinternalid>   <serviceinternalidresets>0</serviceinternalidresets> </waivenrc> <waivenrc>   <typeidnrc>13256</typeidnrc>   <serviceinternalid>98602440</serviceinternalid>   <serviceinternalidresets>0</serviceinternalidresets> </waivenrc> <waivenrc>   <typeidnrc>14046</typeidnrc>   <serviceinternalid>98602440</serviceinternalid>   <serviceinternalidresets>0</serviceinternalidresets> </waivenrc> </waivenrclist> </request> 

the end result want achieve nrclist = nrclist-waivenrclist. want exclude on matching records on basis of typeidnrc, serviceinternalid, serviceinternalidresets below result xml

<request>   <nrclist>     <nrc>       <typeidnrc>13006</typeidnrc>       <serviceinternalid>98602440</serviceinternalid>       <serviceinternalidresets>0</serviceinternalidresets> <viewableonly>1</viewableonly> </nrc> <nrc> <typeidnrc>14098</typeidnrc> <serviceinternalid>98602440</serviceinternalid> <serviceinternalidresets>0</serviceinternalidresets> <viewableonly>1</viewableonly>     </nrc> </nrclist> </request>  

another approach:

here's example copies nrc elements not have matching record in waivenrclist- based on matching typeidnrc:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <xsl:key name="waive" match="waivenrc" use="typeidnrc" />  <xsl:template match="/">     <request>         <nrclist>             <xsl:for-each select="request/modifyproductsandpackages/nrclist/nrc[not(key('waive', typeidnrc))]">                 <xsl:copy-of select="."/>             </xsl:for-each>         </nrclist>     </request> </xsl:template>  </xsl:stylesheet> 

applied input example, result is:

<?xml version="1.0" encoding="utf-8"?> <request>    <nrclist>       <nrc>          <typeidnrc>13006</typeidnrc>          <serviceinternalid>98602440</serviceinternalid>          <serviceinternalidresets>0</serviceinternalidresets>          <viewableonly>1</viewableonly>       </nrc>       <nrc>          <typeidnrc>14098</typeidnrc>          <serviceinternalid>98602440</serviceinternalid>          <serviceinternalidresets>0</serviceinternalidresets>          <viewableonly>1</viewableonly>       </nrc>    </nrclist> </request> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -