View Single Post
  #2 (permalink)  
Old March 2nd, 2010, 08:12 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Assuming you're using XSLT 2.0, there's a neat trick for this discovered by David Carlisle (if I remember right).

Code:
<xsl:for-each-group select="link" group-adjacent="number(.) - position()">
   <xsl:for-each select="current-group()">
      <xsl:choose>
       <xsl:when test="position() = 1 and count(current-group()) = 1">
         <xsl:copy-of select="."/>
       </xsl:when>
       <xsl:when test="position() = 1">
          <link><xsl:value-of select="concat(., '--', current-group()[last()]"/></link>
       </xsl:when>
       <xsl:otherwise>
            <link/>
       </
      </
   </
</
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference