This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
multi-level grouping trouble
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] multi-level grouping trouble
- From: "Dave Gomboc" <dave at cs dot ualberta dot ca>
- Date: Mon, 2 Apr 2001 00:23:48 -0600
- Reply-To: xsl-list at lists dot mulberrytech dot com
Yes, I've looked at Jeni's example message on multi-level grouping. I'm
still having trouble with this, though, and would appreciate if someone
could point out what I'm still doing incorrectly. I think that the
first-level grouping is okay, but that the second-level is hosed.
The one-letter tags are of dual purpose: you can think of "i" as
instance, "s" as standard_name, "u" as used_name, or you can think of
all of them as html output formatting tags to help with debugging!
<grin> (That's why the doctype is currently commented out.)
Sample Data:
<?xml version="1.0" encoding="US-ASCII"?>
<root>
<i><s>Dunton, John</s><u>John Dunton</u><e id="1"/></i>
<i><s>Dunton, John</s><u>Johnnie</u><e id="1"/></i>
<i><s>Sault, Richard</s><u>Richard Sault</u><e id="1"/></i>
<i><s>Norris, John</s><u>John Norris</u><e id="1"/></i>
<i><s>Wesley, Samuel</s><u>Samuel Wesley, the elder</u><e id="1"/></i>
<i><s>Dunton, John</s><u>John Dunton</u><e id="2"/></i>
<i><s>Dunton, John</s><u>John Dunton</u><e id="3"/></i>
<i><s>Sault, Richard</s><u>Richard Sault</u><e id="3"/></i>
<i><s>Norris, John</s><u>John Norris</u><e id="3"/></i>
<i><s>Wesley, Samuel</s><u>Samuel Wesley</u><e id="3"/></i>
<i><s>Haywood, Eliza</s><u>Eliza Haywood</u><e id="7"/></i>
<i><s>Haywood, Eliza</s><u>Eliza</u><e id="8"/></i>
</root>
Code that I'm transforming the above data with:
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:transform
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
exclude-result-prefixes="saxon">
<xsl:output
method="xml"
indent="yes"
encoding="US-ASCII"
/>
<!--
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
-->
<xsl:key
name="i_by_s"
match="i"
use="s"/>
<xsl:key
name="i_by_su"
match="i"
use="concat(s,' ',u)"/>
<xsl:template match="root">
<html>
<body>
<table border="2">
<xsl:for-each select="i[generate-id(.) =
generate-id(key('i_by_s',s)[1])]">
<xsl:sort select="s"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="i">
<tr><td><h3><xsl:value-of select="s"/></h3></td></tr>
<xsl:for-each select="s[generate-id(u) =
generate-id(key('i_by_su',u)[1])]">
<xsl:sort select="b"/>
<xsl:sort select="e"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="s">
<tr><td><h6><xsl:value-of select="../u"/></h6></td></tr>
<xsl:variable name="standard_names" select="key('i_by_s', .)"/>
<xsl:variable name="wanted_standard_name_and_user_name_pair"
select="concat(.,' ',../u)"/>
<xsl:for-each select="$standard_names[generate-id(.) =
generate-id(key('i_by_su',$wanted_standard_name_and_user_name_pair)[1])]
">
<tr><td><xsl:value-of select="e/@id"/></td></tr>
</xsl:for-each>
</xsl:template>
</xsl:transform>
Intended result:
I'm trying to sort on "s", then "u", then print out a bunch of stuff
based on matching 's' and 'u'. I've left in <e id='blah'> tags, but
there's actually other stuff that would be siblings of e (direct
children of i) that I want to print out too. (Actually, I may need to
do more grouping!) Eventually, I probably want a treeview, but I'm not
too worried about the display at this point, so I'm just using a
single-column table, sticking each item in the next row, e.g.:
Dunton, John
John Dunton
1
2
3
Johnnie
1
Haywood, Eliza
Eliza
8
Eliza Haywood
7
Norris, John
John Norris
1
3
Sault, Richard
Richard Sault
1
3
Wesley, Samuel
Samuel Wesley
3
Samuel Wesley, the elder
1
I am in control of the format of the input data: should rearranging its
layout be of benefit, I can do that. The real data is far too large to
contemplate the use of the preceding-sibling axis. I am willing to use
saxon:intersection, since I'm already using saxon:preview just to be
able to create the input data in the first place.
Dave
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list