[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

thanks Re: multi-level grouping trouble

Subject: thanks Re: multi-level grouping trouble
From: "Dave Gomboc" <dave@xxxxxxxxxxxxxx>
Date: Tue, 3 Apr 2001 16:01:12 -0600
saxon has same nodes
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.