Subject: Re: [xsl] Generate sequences of the permutations of a set From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 18 Nov 2017 21:57:51 -0000 |
I'd probably avoid string operations until the end, this implements it essentially as counting base $b except using digits 1-n not 0-n the, then just replaces the numeric digits by the values from the elements (the alphabet $a) <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:n="data:n" exclude-result-prefixes="n" > <xsl:template match="set"> <xsl:sequence select="n:f(element/string(.),count(element),0)"/> </xsl:template> <xsl:function name="n:f"> <xsl:param name="a"/> <xsl:param name="b"/> <xsl:param name="x"/> <xsl:if test="count($x) le $b"> <sequence><xsl:sequence select="for $i in $x return $a[$i]"/></sequence> <xsl:sequence select="n:f($a,$b,n:add($b,$x))"/> </xsl:if> </xsl:function> <xsl:function name="n:add"> <xsl:param name="b"/> <xsl:param name="x"/> <xsl:sequence select="if(empty($x)) then 1 else if($x[last()] lt $b) then ($x[position()!=last()],$x[last()]+1) else (n:add($b,$x[position()!=last()]),1)"/> </xsl:function> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Generate sequences of the, Costello, Roger L. c | Thread | [xsl] Re: Adjacent grouping?, rus tle profrustylea |
Re: [xsl] Generate sequences of the, Costello, Roger L. c | Date | [xsl] Re: Adjacent grouping?, rus tle profrustylea |
Month |