View Single Post
  #4 (permalink)  
Old March 2nd, 2010, 08:54 AM
Martin Honnen Martin Honnen is offline
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

What Michael posted outlines the grouping for those 'link' elements, as you have other child elements and also some link elements which already have a "range" I think you need an additional grouping construct as follows:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="index-item">
    <xsl:copy>
      <xsl:for-each-group select="node()" group-adjacent="boolean(self::link[matches(., '^[0-9]+$')])">
        <xsl:choose>
          <xsl:when test="current-grouping-key()">
            <xsl:for-each-group select="current-group()" group-adjacent="number(.) - position()">
              <xsl:for-each select="current-group()">
                <xsl:choose>
                  <xsl:when test="position() eq 1 and count(current-group()) eq 1">
                    <xsl:copy-of select="current-group()"/>
                  </xsl:when>
                  <xsl:when test="position() eq 1">
                    <link><xsl:value-of select="concat(current-group()[1], '--', current-group()[last()])"/></link>
                  </xsl:when>
                  <xsl:otherwise>
                    <link/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each-group>
          </xsl:when>
          <xsl:otherwise>
            <xsl:copy-of select="current-group()"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
anil_yadav26@hotmail.com (March 2nd, 2010)