Another mind-blowing solution. This one from Michael Kay:
<!--
Determine if the ranges in $seq are consecutive.
$seq = (0-2, 3-7, 8, 9-15) returns true
$seq = (0-3, 3-7, 8, 9-15) returns false
-->
<xsl:function name="f:isConsecutive" as="xs:boolean">
<xsl:param name="seq"/>
<xsl:variable name="seq-with-to" as="xs:integer*">
<xsl:evaluate xpath="$seq ! replace(., '-', ' to ') =>
string-join(',')"/>
</xsl:variable>
<xsl:sequence select="deep-equal($seq-with-to, $seq-with-to[1] to
$seq-with-to[last()])"/>
</xsl:function>
|