[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: 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
|
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
|