Subject: Re: [xsl] counting nodes based on text within From: Jörg Heinicke <joerg.heinicke@xxxxxx> Date: Tue, 23 Oct 2001 23:29:33 +0200 |
If you know the values of choices, you can do the following: <xsl:value-of select="count(/thexml/line/choice[.='item a'])"/> A more generic version you can have with keys. My example uses the Muenchian Method (http://www.jenitennison.com/xslt/grouping/muenchian.xml). <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:key name="choices" match="choice" use="text()"/> <xsl:template match="thexml"> <xsl:for-each select="line/choice[count(.|key('choices',text())[1])=1]"> <xsl:value-of select="text()"/> <xsl:value-of select="count(key('choices',text()))"/> </xsl:for-each> </xsl:template> </xsl:stylesheet> Hope this helps, Joerg ----- Original Message ----- From: "Nouwens, H.J.P." <H.J.P.Nouwens@xxxxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, October 23, 2001 3:51 PM Subject: [xsl] counting nodes based on text within > Hi there, can you help me? > I have a piece of xml like this. I want to convert it to al list (table) of > date, email adresses and choice. That I can do, that's easy. > Now I want to start of the page with a summary like: > > number of people choose "item a" is 2 > number of people choose "item b" is 1 > > The number of choices is limited to 5. I'm willing to duplicate a piece of > code 5 times :-) But a generic solution will surely be nicer... > > Thanks! > > <thexml> > <line date="10-22-2001,11:32:01"> > <Email>h.j.p.nouwens@xxxxxxxxxxxxxxx</Email> > <choice>item a</choice> > </line> > <line date="10-22-2001,11:33:04"> > <Email>h.j.p.nouwens@xxxxxxxxxxxxxxx</Email> > <choice>item b</choice> > </line> > <line date="10-22-2001,11:36:26"> > <Email>J.Jansen@xxxxxxxxxxxxxxx</Email> > <choice>item a</choice> > </line> > </thexml> > > Hans Nouwens XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] counting nodes based on text , Nouwens, H.J.P. | Thread | [xsl] Nodesets as parameters, Hunsberger, Peter |
RE: [xsl] Writing to file vs. stori, Michael Kay | Date | Re: [xsl] Max value from a table, Jörg Heinicke |
Month |