[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

Subject: Re: 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
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.