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

Re: How to tell the number of distinct attribute values?

Subject: Re: How to tell the number of distinct attribute values?
From: "Nikolai Grigoriev" <grig@xxxxxxx>
Date: Thu, 23 Mar 2000 11:45:01 +0300
xslt select distinct attribute
Yufei Wang wrote:

> The rule is to re-group the items according to their @period value.
> However, I could not figure out a way to tell how many distinct @period
> values there are.

Try the thing below. I've tested it with XT.

Regards,
Nikolai Grigoriev

RenderX

======================================================

<!-- This template lists all grandchildren items sorted by @period  -->
<!-- and calls a group building template for every first occurrence -->
<!-- of @period value (tested in xsl:if ).                          -->

<xsl:template match="group">
  <group>
  <xsl:for-each select="group/item">
    <xsl:sort select="@period"/>
    <xsl:variable name="year" select="@period"/>

    <!-- Check if this value is mentioned for the first time -->
    <xsl:if test="not (preceding-sibling::item[@period=$year]) 
            and not (../preceding-sibling::group/item[@period=$year])">
      <xsl:apply-templates select="../.." mode="enumerate-items">
        <xsl:with-param name="selected-year" select="$year"/>
      </xsl:apply-templates>
    </xsl:if>

  </xsl:for-each>
  </group>
</xsl:template>


<!-- This template builds a group of items for a given year. -->
<!-- It is applied to the same node as the above one, but    -->
<!-- in a different mode.                                    -->

<xsl:template match="group" mode="enumerate-items">
  <xsl:param  name="selected-year"/>
  <group>
    <xsl:apply-templates select="group/item[@period=$selected-year]" 
                         mode="copy"/>
  </group>
</xsl:template>


<!-- Auxiliary template: when in copy mode, copy everything through -->

<xsl:template match="*|@*|comment()|text()" mode="copy">
  <xsl:copy>
    <xsl:apply-templates select="*|@*|comment()|text()" mode="copy"/>
  </xsl:copy>
</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.