Re: [xsl] Unique question

Subject: Re: [xsl] Unique question
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 5 Oct 2001 02:09:12 +0200
Hi Darren,

"unique" is a good usage for keys. I only want to point out THE site for
grouping with Muenchian Method:

http://www.jenitennison.com/xslt/grouping/muenchian.xml.

And my solution of your problem:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
    <xsl:output method="html"/>
    <xsl:key name="indices-per-group" match="*[@index]"
        use="concat(generate-id(ancestor::group),'::',@index)"/>

    <xsl:template match="/root-element/group">
        <xsl:value-of select="concat('group ',position(),':')"/>
        <br/>
        <xsl:text># of uniques: </xsl:text>
        <xsl:value-of
            select="count(descendant::*[@index]
            [count(.|key('indices-per-group',concat(generate-id(current()),
            '::',@index))[1])=1])"/>
        <br/>
        <xsl:apply-templates
            select="descendant::*[@index]
            [count(key('indices-per-group',concat(generate-id(current()),
            '::',@index))) > 1][generate-id()=generate-id(key('indices-per-
            group',concat(generate-id(current()),'::',@index))[1])]"/>
    </xsl:template>

    <xsl:template match="*[@index]">
        <xsl:value-of select="concat('There are ',
            count(key('indices-per-group',concat(generate-id(
            ancestor::group),'::',@index))),' elements with
            @index=',@index)"/>
        <br/>
    </xsl:template>
</xsl:stylesheet>

I hope it's still a bit readable and understandable. Of course you can ask,
if you have questions.

Joerg


----- Original Message -----
From: Darren Hayduk
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Sent: Thursday, October 04, 2001 11:32 PM
Subject: [xsl] Unique question


I'm trying to take the XPath expression "*/*/@index" and determine how many
unique vales there are - within my current context.
I've tried various axis expressions and can't seem to figure it out... I'd
be happy with either:
A. the ability to count the unique nodes (and I'll compare to count of all
nodes)
B. just knowing there are duplicates.

Example: Within each group, the table and view indexes need to be unique.
Data in first group is OK, the 'view' in the second group is a duplicate...

<group>
<tables>
<table index="1"/>
<table index="2"/>
</tables/>
<views>
<view index="3"/>
<view index="4"/>
</views/>
</group>
<group>
<tables>
<table index="1"/>
</tables/>
<views>
<view index="1"/>
</views/>
</group>

Thanks,
Darren


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


Current Thread