Subject: RE: [xsl] xslt 2 grouping From: DPawson@xxxxxxxxxxx Date: Thu, 11 Jul 2002 16:15:17 +0100 |
> ><p> > ><el att='a'>x</el> > ><el att='b'>x</el> > ><el att='c'>x</el> > ><el att='d'>y</el> > ></p> > >I have about 1200 lines of this, so keys are out. > > Why discount keys? Because I have so many variants on (above) x, y. ditto on the att values, so I would have to define about 200 unique keys. > > >I want to find all the el elements with content 'a' > >which have *different* att attribute values, > > > >to produce > > > ><el name='x'>a b c </el> > > Below is a solution that doesn't use keys. I've added this > technique to > the Sorting/Grouping section of my XSLT training and the > students have > found it useful. > > >I.e. list x, together with all the attributes att > >which are different. > > > >I'm guessing its a good one for xslt 2, for-each and group-by, > >but I'm stumped on the syntax. > > Are you required to use XSLT-2? No, but it looks like the xslt 2 group-by would be along the right lines, a solution based roughly along the lines of what you have below is still running 15 minutes later. <xsl:template match='el'> <xsl:variable name='f' select='@att'/> <xsl:variable name='p' select='.'/> <row><entry><xsl:value-of select='.'/></entry> <entry> <xsl:value-of select='@f'/>, <xsl:for-each select="following-sibling::p[. = $p]"> <xsl:if test='not(@f=$f)'> <xsl:value-of select='@f'/> </xsl:if> <xsl:if test='not(position()=last())'>, </xsl:if> </xsl:for-each> </entry> </row> </xsl:template> Though I hadn't used the generate-id test for uniqueness Ken, that would be a more efficient solution, I'll try it. thanks DaveP. - NOTICE: The information contained in this email and any attachments is confidential and may be legally privileged. If you are not the intended recipient you are hereby notified that you must not use, disclose, distribute, copy, print or rely on this email's content. If you are not the intended recipient, please notify the sender immediately and then delete the email and any attachments from your system. RNIB has made strenuous efforts to ensure that emails and any attachments generated by its staff are free from viruses. However, it cannot accept any responsibility for any viruses which are transmitted. We therefore recommend you scan all attachments. Please note that the statements and views expressed in this email and any attachments are those of the author and do not necessarily represent those of RNIB. RNIB Registered Charity Number: 226227 Website: http://www.rnib.org.uk XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xslt 2 grouping, G. Ken Holman | Thread | Re: [xsl] xslt 2 grouping, David Carlisle |
Re: [xsl] xslt 2 grouping, David Carlisle | Date | [xsl] substring function, CROFT, MICHAEL |
Month |