[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: String Combination

Subject: Re: Re: String Combination
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Wed, 13 Mar 2002 22:44:32 -0000
string combination
Hi,

This takes a node, makes a node-set using each of its letters and then
passes it to Dimitre's nice permutation code.  This does of course, require
the msxml node-set extension function.  Hopefully it will help anyway...

==xml==
<root>
<node>abcd</node>
</root>
('hellow' produced too many results for a post!)

==output==
<?xml version="1.0" encoding="UTF-16">
abcd;abdc;acbd;acdb;adbc;adcb;bacd;badc;bcad;bcda;bdac;bdca;cabd;cadb;cbad;c
bda;cdab;cdba;dabc;dacb;dbac;dbca;dcab;dcba;

cheers
Andrew

==xsl==
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:variable name="letterNodeSet">
  <root>
  <xsl:call-template name="nodeSetMaker">
    <xsl:with-param name="theString" select="root/node"/>
  </xsl:call-template>
  </root>
</xsl:variable>

<xsl:template match="/">
  <xsl:call-template name="permutations">
    <xsl:with-param name="nodes"
select="msxsl:node-set($letterNodeSet)/root/letter"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="nodeSetMaker">
  <xsl:param name="theString"/>
  <xsl:choose>
    <xsl:when test="string-length($theString)">
      <xsl:element name="letter">
        <xsl:value-of select="substring($theString,1,1)"/>
      </xsl:element>
      <xsl:call-template name="nodeSetMaker">
        <xsl:with-param name="theString"
         select="substring($theString,2)"/>
      </xsl:call-template>
    </xsl:when>
  </xsl:choose>
</xsl:template>


<xsl:template name="permutations">
  <xsl:param name="nodes" select="/.."/>
  <xsl:param name="current"/>
  <xsl:param name="delimiter" select="';'"/>

  <xsl:choose>
    <xsl:when test="not($nodes)">
      <xsl:value-of select="concat($current, $delimiter)"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:for-each select="$nodes">
        <xsl:variable name="thisPosition" select="position()"/>
        <xsl:call-template name="permutations">
          <xsl:with-param name="nodes"
            select="$nodes[position() != $thisPosition]"/>
          <xsl:with-param name="current"
           select="concat($current, .)"/>
       </xsl:call-template>
     </xsl:for-each>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.