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 (was: if or template?)


I posted something very similar about a month ago to XML-L - it was my
last-ditch attempt to get around the (disturbing) lack of the preceding::
axis in MSXML3:

<xsl:for-each select="//favouritebook">
  <xsl:variable name="thisTitle" select="@title"/>
  <xsl:if test="generate-id(@title)=generate-id(//@title[.=$thisTitle])">
    ...
  </xsl:if> 
</xsl:for-each>

Using xsl:key is more elegant (and almost certainly faster) than using a
variable and xsl:if, as I did; however, since generate-id returns the
generated identifier for the first node in a node-set passed to it, the call
can be simplified somewhat:

<xsl:for-each
select="//tracker-id[generate-id(.)=generate-id(key('tid',.))]">

- Kevin

Kevin Williams
XML Architect
Ultraprise Corporation

> -----Original Message-----
> From: Kay Michael [mailto:Michael.Kay@icl.com]

> This is the traditional solution; Steve Muench has just told 
> me about a
> brilliant alternative using keys:
> 
> <xsl:key name="tid" use="tracker-id" select="."/>
> 
> <xsl:for-each
> select="//tracker-id[generate-id(.)=generate-id(key('tid',.)[1])]">
> 


 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]