xsl-list
[Top] [All Lists]

Re: number collapsing

2004-12-14 06:27:29

range.xml

<a>
<r><x>1</x><x>3</x><x>5</x><x>7</x></r>
<r><x>1</x><x>2</x><x>3</x><x>4</x></r>
<r><x>1</x><x>2</x><x>3</x><x>8</x></r>
</a>


range.xsl
<xsl:stylesheet
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";


<xsl:template match="r">
<xsl:text>
[</xsl:text>
<xsl:for-each-group select="x" group-adjacent="if (position()=1 or 
.=preceding-sibling::x[1]+1) then -1 else position() ">
<xsl:value-of select="."/>
<xsl:if test="current-group()[2]">
<xsl:text>-</xsl:text>
<xsl:value-of select="current-group()[last()]"/>
</xsl:if>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each-group>
<xsl:text>]</xsl:text>
</xsl:template>


</xsl:stylesheet>



$ java -jar ../saxon8/saxon8.jar  range.xml range.xsl
<?xml version="1.0" encoding="UTF-8"?>

[1,3,5,7]

[1-4]

[1-3,8]


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>