1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <xsl:function name="f:pre-proc" as="xs:integer*">
<xsl:param name="input" as="xs:string" />
<xsl:variable name="regex" select="'(-\d+)?\s*;\s*'" />
<xsl:variable name="x" as="xs:string*" select="distinct-values(tokenize($input, $regex))" />
<xsl:for-each select="$x">
<xsl:sort select="number()" data-type="number" order="ascending" />
<xsl:sequence select="xs:integer(.[normalize-space() != ''])" />
</xsl:for-each>
</xsl:function>
<xsl:function name="f:proc" as="xs:string*">
<xsl:param name="input" as="xs:integer*" />
<xsl:param name="entry" as="xs:string" />
<xsl:param name="seq" as="xs:string*" />
<xsl:variable name="started" as="xs:boolean"
select="xs:boolean(string-length($entry))"
/>
<xsl:choose>
<xsl:when test="count($input)=0">
<xsl:sequence select="$seq" />
</xsl:when>
<xsl:when test="count($input)=1">
<xsl:if test="$started=false()">
<xsl:sequence select="($seq, $input[1])" />
</xsl:if>
<xsl:if test="$started=true()">
<xsl:sequence select="($seq, concat($entry, '-', $input[1]))" />
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$started=true() and $input[2]=$input[1]+1">
<xsl:sequence select="f:proc(subsequence($input, 2, count($input)-1), $entry, $seq)" />
</xsl:when>
<xsl:when test="$started=true() and $input[2]!=$input[1]+1">
<xsl:sequence select="f:proc(subsequence($input, 2, count($input)-1), '', ($seq, concat($entry, '-', xs:string($input[1]))))" />
</xsl:when>
<xsl:when test="$started=false() and $input[2]=$input[1]+1">
<xsl:sequence select="f:proc(subsequence($input, 2, count($input)-1), xs:string($input[1]), $seq)" />
</xsl:when>
<xsl:when test="$started=false() and $input[2]!=$input[1]+1">
<xsl:sequence select="f:proc(subsequence($input, 2, count($input)-1), '', ($seq, xs:string($input[1])))" />
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:function> |
Partager