xsl-list
[Top] [All Lists]

[xsl] Grouping and then more grouping

2011-08-15 16:45:20
I'm trying to group the identical groups by id together such that given

<group xml:id="MILHIS_Yes">
    <name>Yes</name>
    <group xml:id="MILHIS_Vehicles">
      <name>Vehicles</name>
      <group xml:id="MILHIS_Air">
        <name>Air</name>
        <group xml:id="MILHIS_Aeroplane">
          <name>Aeroplane</name>
          <item xml:id="MILHIS_Attack_Aircraft">
            <name>Attack Aircraft</name>
          </item>
        </group>
      </group>
    </group>
  </group>
  <group xml:id="MILHIS_Yes">
    <name>Yes</name>
    <group xml:id="MILHIS_Vehicles">
      <name>Vehicles</name>
      <group xml:id="MILHIS_Air">
        <name>Air</name>
        <group xml:id="MILHIS_Aeroplane">
          <name>Aeroplane</name>
          <item xml:id="MILHIS_Bomber_Aircraft">
            <name>Bomber Aircraft</name>
          </item>
        </group>
      </group>
    </group>
  </group>
<group xml:id="MILHIS_Yes">
    <name>Yes</name>
    <group xml:id="MILHIS_Vehicles">
      <name>Vehicles</name>
      <group xml:id="MILHIS_Sea">
        <name>Sea</name>
        <group xml:id="MILHIS_Ship">
          <name>Ship</name>
          <item xml:id="MILHIS_Aircraft_Carrier">
            <name>Aircraft Carrier</name>
          </item>
        </group>
      </group>
    </group>
  </group>

I'll get a result that merges the like groups together and copies items

<group xml:id="MILHIS_Yes">
    <name>Yes</name>

    <group xml:id="MILHIS_Vehicles">
      <name>Vehicles</name>
      <group xml:id="MILHIS_Sea">
        <name>Sea</name>
        <group xml:id="MILHIS_Ship">
          <name>Ship</name>
          <item xml:id="MILHIS_Aircraft_Carrier">
            <name>Aircraft Carrier</name>
          </item>
        </group>
      </group>

      <group xml:id="MILHIS_Air">
        <name>Air</name>
        <group xml:id="MILHIS_Aeroplane">
          <name>Aeroplane</name>

          <item xml:id="MILHIS_Attack_Aircraft">
            <name>Attack Aircraft</name>
          </item>

          <item xml:id="MILHIS_Bomber_Aircraft">
            <name>Bomber Aircraft</name>
          </item>

        </group>
      </group>
    </group>
  </group>



I've written the following which groups the first level and played
around with getting something that moves to lower group levels as I
need however I'm not sure what to do to descend through each group
joining them together by id.

<xsl:template match="root">
    <root>
      <xsl:call-template name="CopyGroup"/>
    </root>
  </xsl:template>

  <xsl:template name="CopyGroup">
    <xsl:for-each-group select="group" group-by="@xml:id">
      <group xml:id="{@xml:id}">
        <xsl:copy-of select="current-group()/*"/>
      </group>
    </xsl:for-each-group>
  </xsl:template>


Thoughts?

Regards
-- 
Alex Muir
Instructor | Program Organizer - University Technology Student Work
Experience Building
University of the Gambia
http://sites.utg.edu.gm/alex/

Low budget software development benefiting development in the Gambia,
West Africa
Experience of a lifetime, come to Gambia and Join UTSWEB -
http://sites.utg.edu.gm/utsweb/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>