|
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 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| How to tell the number of distinct , Wang, Yufei | Thread | xsl loop for display in drop-down b, Seema Ramanathan |
| passing parameters with spaces to s, Warren Hedley | Date | Re: Future XSLT extensions. documen, David Carlisle |
| Month |