Subject: [xsl] Re: Unique question From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Fri, 5 Oct 2001 00:06:37 -0700 (PDT) |
Good Morning, Now, when I'm completely awake, I see that the problem was to count the unique "index" attributes ***within a group***. Certainly, the solution to this is slightly different: First we define a key: <xsl:key name="kIndex" match="@index" use="concat(generate-id(../../..), '~',.)"/> Then if $x contains the position of the "group", for which we need to know the count of unique "index" attributes, the following XPath expression returns this count: count( /groups/group[$x]/*/*/@index[generate-id() = generate-id(key('kIndex', concat(generate-id(/groups/group[$x]), '~', .) )[1] ) ] ) Using the source xml provided, this returns: 4 --- when $x = 1 1 --- when $x = 2 Cheers, Dimitre Novatchev. --- Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote: > Or you can just use: > > <xsl:value-of select="count(/*/*/*/*/@index > [generate-id() > = > generate-id(key('kIndex', .)[1])])"/> > > Cheers, > Dimitre Novatchev. > > --- Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote: > > Hi Daren, > > > > This is a short solution: > > > > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output method="text"/> > > <xsl:key name="kIndex" match="@index" use="."/> > > <xsl:template match="/"> > > <xsl:variable name="x"> > > <xsl:for-each select="/*/*/*/*/@index > > [generate-id() > > = > > generate-id(key('kIndex', .)[1])]"> > > <xsl:value-of select="'Z'"/> > > </xsl:for-each> > > </xsl:variable> > > > > <xsl:value-of select="string-length($x)"/> > > </xsl:template> > > </xsl:stylesheet> > > > > It produces: > > > > 4 > > > > with the corrected version of your xml source (it was not well-formed): > > > > <groups> > > <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> > > </groups> > > > > Hope this helped. > > > > Cheers, > > Dimitre Novatchev. > > > > > > Darren Hayduk <dhayduk at nauticusnet dot com> wrote: > > > > 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> > > > > > > > > > > __________________________________________________ > > Do You Yahoo!? > > NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. > > http://geocities.yahoo.com/ps/info1 > > > > > __________________________________________________ > Do You Yahoo!? > NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. > http://geocities.yahoo.com/ps/info1 > __________________________________________________ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Unique question, Dimitre Novatchev | Thread | [xsl] RE: Unique question, Darren Hayduk |
[xsl] Multiple extension classes wi, Yash | Date | [xsl] keys and idrefs, DPawson |
Month |