This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: grouping headers


Hi Dan,

> I tried your suggestion of using xsl:key instead of my (fixed up)
> rather plodding solution. I found no significant difference in the
> performance of the two.

That surprises me. Would you mind sharing the stylesheets that you
tried? I tried testing with MSXML (using -t to get timing information)
and there was a substantial difference between the following two
templates:

--- using keys ---
<xsl:key name="people" match="person" use="city" />

<xsl:template match="/">
  <xsl:for-each
      select="people/person[count(.|key('people', city)[1]) = 1]">
    <xsl:value-of select="city" />
    <xsl:for-each select="key('people', city)">
      <xsl:value-of select="name" />
    </xsl:for-each>
    <xsl:text>&#xA;</xsl:text>
  </xsl:for-each>
</xsl:template>
---

--- using preceding-sibling ---
<xsl:template match="/">
  <xsl:for-each
      select="people/person[not(preceding-sibling::person/city = city)]">
    <xsl:value-of select="city" />
    <xsl:for-each
        select="/people/person[city = current()/city]">
      <xsl:value-of select="name" />
    </xsl:for-each>
    <xsl:text>&#xA;</xsl:text>
  </xsl:for-each>
</xsl:template>
---

With 1000 person elements, in MSXML the execution time of the key
version took about 100ms whereas the preceding-sibling version took
about 2300ms.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]