View Single Post
  #3 (permalink)  
Old March 2nd, 2010, 08:46 AM
anil_yadav26@hotmail.com anil_yadav26@hotmail.com is offline
Authorized User
 
Join Date: Feb 2009
Location: Gurgaon
Posts: 31
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to anil_yadav26@hotmail.com
Default

Hi Michael,

Thanks for your response!

I run the suggested code but its creating the page range for first and last node of group whereas I need range only for continuous page numbers. In the below example (red) you can see input xml file coding and blue contains output xml coding. The blue part contains two information first is continuous page range and independent page number.

<link>410</link><link>411</link><link>412</link><link>413</link><link>420</link>

and need to transform like this:

<link>410--413</link><link></link><link></link><link></link><link>420</link>


XSLT
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    exclude-result-prefixes="xs" 
    version="2.0">
 <xsl:template match="index-item">
  <xsl:for-each-group select="link" group-adjacent="number(link) - 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/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
 </xsl:for-each-group>
  </xsl:template>
</xsl:stylesheet>
Could you please look into this and do the needful.

Thanks,
Anil Yadav
Reply With Quote