This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Filter nodes by attribute and output disgarded dups
- From: "Joerg Heinicke" <joerg dot heinicke at gmx dot de>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 7 Jan 2002 22:45:13 +0100
- Subject: Re: [xsl] Filter nodes by attribute and output disgarded dups
- References: <20020107162046.58970.qmail@web10108.mail.yahoo.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
> Here is my xsl attempts:
> <xsl:for-each
> select="//C03//PERSNAME[@ROLE='arr'](not[.=preceding::PERSNAME])">
> <xsl:sort select="."/>
> <LI><xsl:value-of select="."/>
> <xsl:text>     : </xsl:text>
> <xsl:value-of select="count(.//PERSNAME[@ROLE='arr'])"/>
> </LI>
> </xsl:for-each>
Hi Mike,
the not() has to be within the squared brackets. And the context of your
counting must be "brought back" to the root element. <xsl:for-each> changes
the context and .//PERSNAME is always 0.
But what's with keys? It's much to easier to do that with keys:
<xsl:key name="persnames" match="PERSNAME[@ROLE='arr']" use="."/>
<xsl:for-each select="//C03//PERSNAME[@ROLE='arr'][count(. |
key('persnames', .)[1] ) = 1]">
<xsl:sort select="."/>
<LI>
<xsl:value-of select="concat(.,
'     : ', count(key('persnames',.)))/>
</LI>
</xsl:for-each>
Regards,
Joerg
----- Original Message -----
From: "Mike Ferrando" <mikeferrando@yahoo.com>
> Friends,
> I am attempting to pull node data conditioned by the attribute value.
>
> <PERSNAME ROLE="arr">Smith, John</PERSNAME>
>
> I am having trouble writing the syntax. The reason is that I am not
> sure how the syntax is delimited. I keep getting parsing errors
> "Unexpected token". I take it that I cannot have "[]" followed by
> "()". How can I write this using an attribute in the expression?
>
> What I would like to do is:
> 1. sort by name of arranger.
> 2. filter out the duplicates
> 3. capture the number of duplicates
> 4. output each name and the number of times it appears
>
> Here is my xml and my xsl:
>
> <C02>
> <DID>
> <UNITTITLE>
> <PERSNAME ENCODINGANALOG="100$a">Abt, Franz</PERSNAME>
> </UNITTITLE>
> </DID>
> <C03>
> <DID>
> <CONTAINER TYPE="BOX">22</CONTAINER>
> <UNITTITLE ID="PV106">
> <TITLE>Schalf wohl, du süsser Engel du, op. 139</TITLE>
> <PERSNAME ENCODINGANALOG="700$a" ROLE="arr">Hennes,
> Aloys</PERSNAME>
> <GEOGNAME ENCODINGANALOG="260$a">London</GEOGNAME>
> <CORPNAME ENCODINGANALOG="260$b">Ent. Stat Hall</CORPNAME>
> <UNITDATE ENCODINGANALOG="260$c">[n.d.]</UNITDATE>
> </UNITTITLE>
> </DID>
> <ODD>
> <P>
> <SUBJECT>For piano</SUBJECT>
> </P>
> </ODD>
> </C03>
> </C02>
>
> Here is my xsl attempts:
> <xsl:for-each
> select="//C03//PERSNAME[@ROLE='arr'](not[.=preceding::PERSNAME])">
> <xsl:sort select="."/>
> <LI><xsl:value-of select="."/>
> <xsl:text>     : </xsl:text>
> <xsl:value-of select="count(.//PERSNAME[@ROLE='arr'])"/>
> </LI>
> </xsl:for-each>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list