Subject: Re: [xsl] Filter nodes by attribute and output disgarded dups From: "Joerg Heinicke" <joerg.heinicke@xxxxxx> Date: Mon, 7 Jan 2002 22:45:13 +0100 |
> 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@xxxxxxxxx> > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Filter nodes by attribute and, Mike Ferrando | Thread | Re: [xsl] Filter nodes by attribute, Mike Ferrando |
Crossposting (Was: Re: Case of func, Mulberry Technologie | Date | RE: XPath's role (Was: Re: [xsl] Re, Michael Kay |
Month |