IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

XSLT - 2 level grouping & sequencing

  • 1.  XSLT - 2 level grouping & sequencing

    Posted Fri June 17, 2005 06:33 PM

    Hi,

    I need a help in doing 2 level grouping (& sequencing - mentioned later) on my XML - Thanks in advance for any

    input : I want to do it in XSLT 1.0 (not 2.0)

    I - 2 level grouping
    input XML:

    <?xml version="1.0" encoding="utf-8"?> 100 01 200 02 100 02 300 03 100 08

    Expected output XML:

    <?xml version="1.0" encoding="utf-8"?> 100 01 02 08 200 02 300 03

    Description:
    As you may notice from the above, I want to group all the level2’s that have the same Level1 keys. (see the

    one with L1key value 100).
    How do I do that? My XSLT is given below - but it only displays one Level2 (not all of them)

    XSLT:
    <xsl:stylesheet version=“1.0” xmlns:xsl=“XSLT Namespace”

    xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xs=“XML Schema”

    exclude-result-prefixes=“xs”>
    <xsl:output method=“xml” encoding=“UTF-8” indent=“yes”/>
    <xsl:key name=“L1key” match=“Level1” use=“L1key”/>
    <xsl:template match=“/File”>

    <xsl:attribute

    name=“xsi:noNamespaceSchemaLocation”>C:/BTPOC2~1/XSLTTE~1/out_xsd.xsd</xsl:attribute>

            <xsl:for-each select="Level1[generate-id()=generate-id(key('L1key',L1key))]">
    <L1>
    <L1key>
    <xsl:for-each select="L1key">
    <xsl:value-of select="."/>
    </xsl:for-each>
    </L1key>
    
    <xsl:for-each select="Level2">
    <L2>
    <xsl:for-each select="L2key">
    <L2key>
    <xsl:value-of select="."/>
    </L2key>
    </xsl:for-each>
    </L2>
    </xsl:for-each>
    
    </L1>
    </xsl:for-each>
    </File>
    </xsl:template>
    

    </xsl:stylesheet>

    II - sequencing:

    In the above, for example, if I expand the output XML - level 2 as
    01, i.e. to introduce the sequence # to identify each L2key value uniquely ,

    how do I do that?

    Thanks,
    Ken


    #API-Management
    #Tamino
    #webMethods


  • 2.  RE: XSLT - 2 level grouping & sequencing

    Posted Sun June 19, 2005 10:12 PM

    Hi

    simply replace the inner loop

          <xsl:for-each select="Level2"> 
    <L2> 
    <xsl:for-each select="L2key"> 
    <L2key> 
    <xsl:value-of select="."/> 
    </L2key> 
    </xsl:for-each> 
    </L2> 
    </xsl:for-each> 
    

    by

          <xsl:for-each select="key('L1key',L1key)"> 
    <L2> 
    <L2key> 
    <xsl:value-of select="./Level2/L2key"/> 
    </L2key> 
    </L2> 
    </xsl:for-each> 
    

    That does what you want

    Uli


    #webMethods
    #API-Management
    #Tamino


  • 3.  RE: XSLT - 2 level grouping & sequencing

    Posted Tue June 21, 2005 12:02 AM

    Thank you very much… God Bless you.


    #Tamino
    #API-Management
    #webMethods