|
Subject: RE: [xsl] xslt 2 grouping From: DPawson@xxxxxxxxxxx Date: Mon, 15 Jul 2002 08:21:43 +0100 |
Mike wrote:
> The XSLT 2.0 solution (untested) is:
>
> <xsl:for-each-group select="e1" group-by=".">
> <e1 name="{.}">
> <xsl:for-each-group select="current-group()" group-by="@att">
> <xsl:value-of select="concat(@att, ' ')"/>
> </xsl:for-each>
> </e1>
> </xsl:for-each>
>
> You could also use distinct-values().
Hint :-) How please?
>
> I don't understand your comment that you can't use keys because there
> are 1200 lines?
As David questionned, and yet again he was right!
Playing at home over the weekend got me this:
Just me and Steve M's logic again!
I'm going to persevere with a 2.0 solution, if nothing else it might
get me a little more familiar with 2.0.
Thanks Mike.
xml test
<doc>
<el fo='fo:block'>
<p>width</p>
<p>height</p>
<p>sum</p>
</el>
<el fo='page'>
<p>width</p>
<p>height</p>
<p>another</p>
</el>
</doc>
xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/"
exclude-result-prefixes='saxon'
version="1.1">
<xsl:output method="xml" indent='yes'/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:key name='prop'
match='p'
use='.'/>
<xsl:template match='doc'>
<doc>
<xsl:for-each
select='el/p[generate-id(.)= generate-id(key("prop",.)[1])] '>
<xsl:variable name='prop' select='.'/>
<p> <prop><xsl:value-of select='.'/></prop><els>
<el><xsl:value-of select='../@fo'/></el>
<xsl:for-each select='following::el[p=$prop]/@fo'>
<el><xsl:value-of select='.'/></el>
</xsl:for-each>
</els></p>
</xsl:for-each>
</doc>
</xsl:template>
<xsl:template match='el'>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match='p'>
<xsl:variable name='fo' select='../@fo'/>
<xsl:variable name='prop' select='.'/>
<xsl:for-each select='//p[not (generate-id(..) =$fo) ]
[.=$prop]'>
<xsl:sort select='.'/>
<prop><p><xsl:value-of select='.'/></p><fo> <xsl:value-of
select='../@fo'/></fo></prop>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-
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, McNally, David | Thread | RE: [xsl] xslt 2 grouping, Michael Kay |
| RE: [xsl] DTD, Jarno . Elovirta | Date | RE: [xsl] xslt 2 grouping - solutio, DPawson |
| Month |