Subject: thanks Re: [xsl] multi-level grouping trouble From: "Dave Gomboc" <dave@xxxxxxxxxxxxxx> Date: Tue, 3 Apr 2001 16:01:12 -0600 |
> That's a little bit astray. You're actually after *i elements* > (again). And you want the *i elements* whose own unique ID is the > same as the first i element returned from the key when you access it > with a key value being the composite s concatenated with u (with a > space separator). Sigh, that's what I get for not reviewing everything carefully after deciding to match on <i> again (at first, I was trying to match on <s> for the second pass, before realising that that wasn't such a hot idea because it made it tougher to use the previous constraint). > key('i_by_s', s)[generate-id() = > generate-id(key('i_by_su', > concat(s, ' ', u))[1])]/s > > Or you could apply templates to the i elements in a different mode. > That's what I would usually do. This was probably my biggest problem, not making use of mode. Thanks for pointing that out -- mode makes the problem much simpler. > One more thing - is there any reason that you're wrapping an > xsl:for-each around an xsl:apply-templates like this: > > <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> The reason is that I had forgotten that <xsl:sort> can be used with <xsl:apply-templates>, so I was doing it manually. :-) > > 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. > > Well you may want to use saxon:hasSameNodes() rather than using > generate-id() to test node equality. For example: > > i[saxon:hasSameNodes(., key('i_by_s', s)[1])] > > I hope that helps, > > Jeni Yes, quite a bit, thank you. Here's the working code that I ended up after reading your suggestions: <?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:apply-templates select="i[generate-id(.) = generate-id(key('i_by_s', s)[1])]" mode="i_by_s"> <xsl:sort select="s"/> </xsl:apply-templates> </table> </body> </html> </xsl:template> <xsl:template match="i" mode="i_by_s"> <tr><td>Standard name: <xsl:value-of select="s"/></td></tr> <xsl:apply-templates select="key('i_by_s',s)[generate-id(.) = generate-id(key('i_by_su', concat(s,' ',u))[1])]" mode="i_by_su"> <xsl:sort select="e"/> </xsl:apply-templates> </xsl:template> <xsl:template match="i" mode="i_by_su"> <tr><td>Used name: <xsl:value-of select="u"/></td></tr> <xsl:apply-templates select="key('i_by_su', concat(s,' ',u))" mode="render_content"> <xsl:sort select="e"/> </xsl:apply-templates> </xsl:template> <xsl:template match="i" mode="render_content"> <tr> <td> <xsl:text>e_id </xsl:text> <xsl:value-of select="e/@id"/> </td> </tr> </xsl:template> </xsl:transform> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] multi-level grouping trou, Jeni Tennison | Thread | [xsl] MS XMLDOM not transforming my, Daniel Newman |
[xsl] Request Off-Post ASP/IIS/XML/, Gollwitzer Brian Con | Date | [xsl] Splitting an XML file based o, Adam Van Den Hoven |
Month |