Project

Profile

Help

Support #3763 » sortForEachGroup.xsl

Test stylesheet demonstrating the grouping behaviour - Andy Yar, 2018-04-27 09:30

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xs f" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f="http://aimtec.cz/EDI">

<xsl:output encoding="UTF-8" indent="yes" method="xml"/>

<!-- document root -->
<xsl:template match="root">
<root>

<!-- test the f:sort works -->
<sortTestOutput>
<xsl:sequence select="f:sort(label)"/>
</sortTestOutput>

<!--
create tuples from-to
expcted output: [1,4],[6,8],[10,12]
-->
<groupedOutput>
<xsl:for-each-group select="f:sort(label)" group-starting-with="label[preceding::label[1] + 1 != .]">
<element>
<from>
<xsl:value-of select="current-group()[1]"/>
</from>
<to>
<xsl:value-of select="current-group()[last()]"/>
</to>
</element>
</xsl:for-each-group>
</groupedOutput>
</root>
</xsl:template>

<xsl:function name="f:sort">
<xsl:param name="unsortedSequence"/>

<xsl:perform-sort select="$unsortedSequence">
<xsl:sort select="." data-type="number"/>
</xsl:perform-sort>
</xsl:function>
</xsl:stylesheet>
(1-1/2)