[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How efficient is DVC? - A grouping example - FIXED

Subject: How efficient is DVC? - A grouping example - FIXED
From: "Robbert van Dalen" <juicer@xxxxxxxxx>
Date: Sat, 22 Mar 2003 22:47:02 +0100
xsl grouping example
This is an update on the previous post. I didn't check if the first two examples
worked correctly (I wrote them out of the top of my head). It should now be
fixed. Sorry for the inconvenience!

Cheers,

RvD


__________________________________________
The first example:

<xsl:template match="cities">
  <xsl:variable name="sorted">
    <xsl:for-each select="./city">
      <xsl:sort select="@country"/>
      <xsl:copy-of select="."/>
    </xsl:for-each>
  </xsl:variable>

  <xsl:variable name="sorted-tree-fragment" select="xalan:nodeset($sorted)/*"/>

<!-- Gets the groups -->
  <xsl:variable name="groups">
    <xsl:apply-templates select="$sorted-tree-fragment"/>
  </xsl:variable>

<!-- Iterate through all the groups -->
  <xsl:for-each select="xalan:nodeset($groups)/*">
    <xsl:variable name="country" select="@id"/>
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <!-- Copy the nodes with the same country -->
      <xsl:copy-of select="$sorted-tree-fragment[@country = $country]"/>
    </xsl:copy>
  </xsl:for-each>
</xsl:template>

____________________________
The second example:

<xsl:template match="city">
  <xsl:variable name="preceding" select="./preceding-sibling::*[1]"/>
  <xsl:if test="not(./@country = $preceding/@country)">
    <group id="{./@country}"/>
  </xsl:if>
</xsl:template>

<xsl:template match="city">
  <xsl:variable name="preceding" select="./preceding-sibling::*[1]"/>
  <xsl:choose>
    <xsl:when test="not(./@country = $preceding/@country)">
      <group id2="{./@country}">
        <xsl:copy-of select="."/>
        <xsl:apply-templates select="./following-sibling::*[1]"/>
      </group>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="."/>
      <xsl:apply-templates select="./following-sibling::*[1]"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<xsl:template match="group">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:copy-of select="./city"/>
  </xsl:copy>
  <xsl:apply-templates select="./group"/>
</xsl:template>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.