Connecting Tech Pros Worldwide Help | Site Map

xsl: How to update varial value in a loop

Newbie
 
Join Date: Jan 2009
Location: Denmark
Posts: 13
#1: Jan 28 '09
I have a xml file:
Expand|Select|Wrap|Line Numbers
  1. <E1MBXYI SEGMENT="1">
  2. ...
  3. <CHARG>1000024187</CHARG> 
  4. ...
  5. </E1MBXYI>
  6. <E1MBXYI SEGMENT="1">
  7. ...
  8. <CHARG>1000024187</CHARG> 
  9. ...
  10. </E1MBXYI>
  11. <E1MBXYI SEGMENT="1">
  12. ...
  13. <CHARG>1000024188</CHARG> 
  14. ...
  15. </E1MBXYI>
  16.  
I want to transform it to another xml file, where I should only take the item CHARG if it has a differetn value.
I wrote the following code:
Expand|Select|Wrap|Line Numbers
  1. <DataArea>
  2.         <xsl:variable name="V_MaterialLot" select="''"/>
  3.         <xsl:for-each select="E1MBXYI">
  4.                 <xsl:if test="$V_MaterialLot != CHARG">
  5.                         <MaterialInformation>
  6.                                 <ID>
  7.                                         <xsl:value-of select="CHARG"/>
  8.                                         <xsl:variable name="V_MaterialLot" select="CHARG"/>
  9.                                 <ID>
  10.                         <MaterialInformation>
  11.                 </xsl:if>
  12.         </xsl:for-each>
  13. </DataArea>
  14.  
However, I can not define the varial V_MaterialLot twice in the same xsl.
Does someone have a solution to me?
Regards
maxin
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Jan 28 '09

re: xsl: How to update varial value in a loop


if you want to use only the unique <CHARG>s, then you can try Muenchian Grouping before doing the output.
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#3: Jan 28 '09

re: xsl: How to update varial value in a loop


More specifically it would be like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="E1MBXYI[not (CHARG = preceding-sibling::E1MBXYI/CHARG)]">
  2.  
No variables needed.
Newbie
 
Join Date: Jan 2009
Location: Denmark
Posts: 13
#4: Jan 28 '09

re: xsl: How to update varial value in a loop


Thanks all for the solution.
I will try it.

Regards maxin
Reply