xsl: How to update varial value in a loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxin
    New Member
    • Jan 2009
    • 13

    #1

    xsl: How to update varial value in a loop

    I have a xml file:
    Code:
    <E1MBXYI SEGMENT="1">
    ...
    <CHARG>1000024187</CHARG> 
    ...
    </E1MBXYI>
    <E1MBXYI SEGMENT="1">
    ...
    <CHARG>1000024187</CHARG> 
    ...
    </E1MBXYI>
    <E1MBXYI SEGMENT="1">
    ...
    <CHARG>1000024188</CHARG> 
    ...
    </E1MBXYI>
    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:
    Code:
    <DataArea>
            <xsl:variable name="V_MaterialLot" select="''"/>
            <xsl:for-each select="E1MBXYI">
                    <xsl:if test="$V_MaterialLot != CHARG">
                            <MaterialInformation>
                                    <ID>
                                            <xsl:value-of select="CHARG"/>
                                            <xsl:variable name="V_MaterialLot" select="CHARG"/>
                                    <ID>
                            <MaterialInformation>
                    </xsl:if>
            </xsl:for-each>
    </DataArea>
    However, I can not define the varial V_MaterialLot twice in the same xsl.
    Does someone have a solution to me?
    Regards
    maxin
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if you want to use only the unique <CHARG>s, then you can try Muenchian Grouping before doing the output.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      More specifically it would be like:
      Code:
      <xsl:for-each select="E1MBXYI[not (CHARG = preceding-sibling::E1MBXYI/CHARG)]">
      No variables needed.

      Comment

      • maxin
        New Member
        • Jan 2009
        • 13

        #4
        Thanks all for the solution.
        I will try it.

        Regards maxin

        Comment

        Working...