how to compare xml elements within root using xslt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sujathaeeshan
    New Member
    • Feb 2008
    • 22

    how to compare xml elements within root using xslt

    hi all,
    here is xml file.....
    <root>
    <Xmltype>
    <owner NAME="Legal Entity 1"></owner>
    <LegalEntity NAME="Legal Entity 1"></LegalEntity>
    <lob NAME="Line Of Business 1"></lob>
    <Formula>A</Formula>
    <Formula>B</Formula>
    </Xmltype>
    <Xmltype>
    <owner NAME="Legal Entity 1"></owner>
    <LegalEntity NAME="Legal Entity 1"></LegalEntity>
    <lob NAME="Line Of Business 1"></lob>
    <Formula>c</Formula>
    <Formula>D</Formula>
    <Formula>B</Formula>
    </Xmltype>
    <Xmltype>
    <owner NAME="Legal Entity 1"></owner>
    <LegalEntity NAME="Legal Entity 1"></LegalEntity>
    <lob NAME="Line Of Business 2"></lob>
    <Formula>A</Formula>
    </Xmltype>
    <Xmltype>
    <owner NAME="Legal Entity 1"></owner>
    <LegalEntity NAME="Legal Entity 1"></LegalEntity>
    <lob NAME="Line Of Business 2"></lob>
    <Formula >B</Formula>
    </Xmltype>
    <Xmltype>
    <owner NAME="Legal Entity 1"></owner>
    <LegalEntity NAME="Legal Entity 1"></LegalEntity>
    <lob NAME="Line Of Business 1"></lob>
    <Formula>F</Formula>
    </Xmltype>

    </root>

    I need XSLT for this.........
    output should obtain like in HTML by using XSLT:

    LegalEntityOwne r:Legal Entity 1
    LegalEntityName :LegalEntity
    LobName:Line Of Business 1
    Formula:A
    Formula:B
    Formula:C
    Formula:D
    Formula:B
    Formula:F

    LegalEntityOwne r:Legal Entity 1
    LegalEntityName :LegalEntity
    LobName:Line Of Business 2
    Formula:A
    Formula:B


    pleas can any one help!!!!
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    As posted elsewhere:

    Muenchian grouping



    [code=xml]
    <xsl:key name="xmltypesB yLob" match="Xmltype" use="lob/@NAME"/>

    <xsl:for-each select="/root/Xmltype[count(.|key('xm ltypesByLob', lob/@NAME)[1]) = 1]">
    <xsl:text>Legal EntityOwner:</xsl:text>
    <xsl:value-of select="owner/@NAME"><br/>
    <xsl:text>Legal EntityName:</xsl:text>
    <xsl:value-of select="LegalEn tity/@NAME"><br/>
    <xsl:text>LobNa me:</xsl:text>
    <xsl:value-of select="lob/@NAME"><br/>
    <xsl:for-each select="key('xm ltypesByLob',lo b/@name)/Formula">
    <xsl:text>Formu la:</xsl:text>
    <xsl:value-of select="."/><br/>
    </xsl:for-each>
    <br/>
    </xsl:for-each>
    [/code]

    Comment

    • sujathaeeshan
      New Member
      • Feb 2008
      • 22

      #3
      Hi,
      I used your approach
      But its displaying like

      LegalEntityOwne r:Legal Entity 1
      LegalEntityName :Legal Entity 1
      LobName:Line Of Business 1

      LegalEntityOwne r:Legal Entity 1
      LegalEntityName :Legal Entity 1
      LobName:Line Of Business 2

      Its not showing the Formula Details......
      Please can you tell me how to display the formula detailsv that belongs to corresponding owner,legal entity ,lob......

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Made a mistake, In the for each change the @name to uppercase: @NAME

        Comment

        Working...