[XSL-LIST Mailing List Archive Home]
[Reply To This Message]
Re: XSLT - Multiple Level Grouping with Unknown Level
Subject: Re: XSLT - Multiple Level Grouping with Unknown Level|
From: "Arun Sinha" <arunsinha666@xxxxxxxxxxx>
Date: Fri, 10 Sep 2004 07:13:55 +0100
Thanks a lot.
You are a STAR.
Actually the XML document deosn't have <Groups> element at the top level.
I will ask my colleagues in UK to incorporate the same. I am based in India.
I am getting the XML file from UK and my responsibility is to write
Even though I stayed in UK for 4 years my English is still not upto mark.
When I said 'fixed level' that meant the number of levels are not known.
I did the coding for 2 levels of grouping after finding the solution on your
I would appreciate if you could put this one, as well, on your website.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
To: "Arun Sinha" <arunsinha666@xxxxxxxxxxx>
Subject: Re: XSLT - Multiple Level Grouping with Unknown Level
Date: Thu, 9 Sep 2004 22:28:28 +0100
> I have just started doing coding in XSLT and stuck with a unique
> problem. I have done the coding for grouping with fixed levels but
> finiding the solution for this one is getting too complicated.
I'll give this a shot, but I'm not sure what you mean by "fixed
levels", so I'm not certain that this will do what you want.
You're lucky in that your source actually already contains the groups
that you need: usually they don't, and people have to manufacture the
groups using keys etc.
I've assumed that you've got a <Groups> element wrapped around the
top-level <Group> elements. Create a table at that level, and insert
the relevant column headers there. Then apply templates to all the
<Row> elements within the <Groups> element: we know we need one row in
the table for each <Row> in the source.
<xsl:apply-templates select=".//Row" />
So we create one row per <Row> in the source. Keep track of the ID of
the row: I'm using generate-id() here, but perhaps your source
actually has a unique identifier that you could use. To fill in the
first set of columns, you need to get the values from the <GroupValue>
elements of the <Group> elements in which the <Row> appears. But you
only want to output them if the row you're on is the first row within
the group. So locate that first row and get its ID ($first-row-id),
and only output the <GroupValue> if that ID matches the one for the
<xsl:variable name="row-id" select="generate-id(.)" />
<xsl:if test="$row-id = $first-row-id">
<xsl:value-of select="GroupValue" />
<xsl:apply-templates select="ColumnValue" />
The rest of the cells are simply the values from the <ColumnValue>
elements: that's very straight-forward:
<td><xsl:value-of select="." /></td>
It's fast, it's easy and it's free. Get MSN Messenger today!
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format