xsl-list
[Top] [All Lists]

Re: RE: [xsl] XSLT2/Saxon: How to group by distinct element values?

2008-10-17 08:28:16
Great, Michael. Thanks a lot!
-------- Original-Nachricht --------
Datum: Fri, 17 Oct 2008 11:30:36 +0100
Von: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: RE: [xsl] XSLT2/Saxon: How to group by distinct element values?


<xsl:template match="root">
  <root>
    <xsl:for-each-group select="data" group-by="group1">
      <group1 name="{current-grouping-key()}">
        <xsl:for-each-group select="current-group()" group-by="group2">
          <group2 name="{current-grouping-key()}">
            <xsl:for-each select="current-group()">
              <group3 name="{group3}"/>
            </
          </
        </
      </
    </
  </
</

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: "Robert Sösemann" [mailto:rsoese(_at_)gmx(_dot_)de] 
Sent: 17 October 2008 11:10
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT2/Saxon: How to group by distinct element values?

Hi, even after reading for one hour about grouping in XSLT2, 
I could not find out how to transform my Source XML to my Result XML. 
Can anybody help me?

Source XML
----------
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <data>
    <group1>MERCEDES</group1>
    <group2>CLK</group2>
    <group3>CLK 320 CDI Coupe</group3>
  </data>
  <data>
    <group1>MERCEDES</group1>
    <group2>CLK</group2>
    <group3>CLK 320 CDI Sedan</group3>
  </data>
  <data>
    <group1>MERCEDES</group1>
    <group2>SLK</group2f>
    <group3>SLK Limousine</group3>
  </data>
  <data>
    <group1>AUDI</group1>
    <group2>A2</group2>
    <group3>A2 Coupe</group3>
  </data>
</root>

Result XML
----------
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <group1 name="MERCEDES">
    <group2 name="CLK">
      <group3 name="CLK 320 CDI Coupe"/>
      <group3 name="CLK 320 CDI Sedan"/>
    </leve2>
    <group2 name="SLK">
      <group3 name="SLK Limousine"/>
    </group>
  </group1>
  <group1 name="AUDI">
    <group2 name="A2">
      <group3 name="A2 Coupe" />
    </group2>
  </group1>
</root>

Thanks in advance
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--

--~------------------------------------------------------------------
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>