Muenchian problem

Discussion in 'XML' started by mike@keeston-pembrokeshire.co.uk, May 9, 2006.

  1. Guest

    Hi,

    I'm trying to apply Muenchian grouping to the XML displayed below but
    having no success, I'm trying to group on the section element, any
    pointers would be much appreciated:

    Thanks,

    Mike

    ---- XML ----
    <?xml version="1.0" encoding="utf-8"?>
    <page>
    <attributes>
    <pagename>The Band</pagename>
    <name>the_band</name>
    <menuname>The Band</menuname>
    <pageidentifier>english/the_band</pageidentifier>
    <status>open</status>
    <lastedited></lastedited>
    </attributes>
    <containers>
    <container name="content">
    <elements>
    <element type="BandMember">
    <name>Luke Skywalker</name>
    <section>Front Row Cornets</section>
    <position>Solo</position>
    <joined>1992</joined>
    <composer>Gershwin</composer>
    <musicpiece>Lazy Trumpeter</musicpiece>
    <bandmoment>something</bandmoment>
    <notes></notes>
    </element>
    <element type="BandMember">
    <name>Joe Bloggs</name>
    <section>Basses</section>
    <position>1st</position>
    <joined>2004</joined>
    <composer>Something</composer>
    <musicpiece>Someething</musicpiece>
    <bandmoment>Something</bandmoment>
    <notes></notes>
    </element>
    <element type="BandMember">
    <name>Some Body</name>
    <section>Front Row Cornets</section>
    <position>1st</position>
    <joined>2003</joined>
    <composer>jkjjkh</composer>
    <musicpiece>hkjhjkh</musicpiece>
    <bandmoment>Test</bandmoment>
    <notes>Some notes</notes>
    </element>
    </elements>
    </container>
    </containers>
    </page>
    ---------------

    --- XSLT ----

    <xsl:key name="section-group" match="element"
    use="@type='BandMember'"/>

    <xsl:template match="/" mode="show">
    <xsl:for-each select="element[generate-id() =
    generate-id(key('section-group',section) [1])]">
    <h1>
    <xsl:value-of select="section"/>
    </h1>
    <xsl:for-each select="key('section-group',section)">
    <xsl:value-of select="name"/>
    <br/>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:template>

    ----------------
    , May 9, 2006
    #1
    1. Advertising

  2. George Bina Guest

    You should use the section in the key as that is what you want to group
    on. Then the for-each selecting element in the document context (/)
    will not select anything. Last, you need either to remove the mode on
    the template or have some other template that applies templates with
    the show mode on the document node. A working stylesheet is below:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:key name="section-group" match="element" use="section"/>

    <xsl:template match="/">
    <xsl:for-each select="//element[generate-id() =
    generate-id(key('section-group',section) [1])]">
    <h1>
    <xsl:value-of select="section"/>
    </h1>
    <xsl:for-each select="key('section-group',section)">
    <xsl:value-of select="name"/>
    <br/>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
    George Bina, May 10, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackenzie
    Replies:
    0
    Views:
    1,095
    Colin Mackenzie
    Jul 3, 2003
  2. Marrow
    Replies:
    2
    Views:
    1,230
    Marrow
    Jul 7, 2003
  3. Tristan Miller

    XSL grouping (Muenchian)

    Tristan Miller, Jan 31, 2005, in forum: XML
    Replies:
    2
    Views:
    546
    Philippe Poulard
    Jan 31, 2005
  4. reclusive monkey
    Replies:
    2
    Views:
    1,375
    reclusive monkey
    Aug 10, 2005
  5. Replies:
    1
    Views:
    625
    Joris Gillis
    Jun 6, 2006
Loading...

Share This Page