[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Generate sequences of the permutations of a set
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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|