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

Re: enumerating combination

Subject: Re: enumerating combination
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Thu, 28 Jun 2007 00:24:48 +0200 (CEST)
Re:  enumerating combination
Matthieu Ricaud wrote:


> It's about a spellchecker. When searching for an experssion
> with say N words, I want to list every combinations of
> suggested words.

  I guess you made an error in your input file (besides the typo
s/valeur/value/), and there should be only 2 As and only 3 Ds.

  So you want to walk from words to words starting at the first word,
in the document order.  For each, either you use its @value or apply
each of its suggest, in the document order.  For suggest, you want to
use its @value and then apply the next word.  Doing so, you construct
the string from step to step.  Where there is no more 'next word', you
output the string and you backtrack:

(drkm)[4] ~/xslt/tests$ cat spell-check.xml
<spellchecker date="Wed Jun 27 17:13:12 CEST 2007">

  <word value="a" exist="false">
    <suggest value="a1"/>
    <suggest value="a2"/>

  <word value="b" exist="true"></word>

  <word value="c" exist="false">
    <suggest value="c1"/>
    <suggest value="c2"/>
    <suggest value="c3"/>

  <word value="d" exist="false">
    <suggest value="d1"/>
    <suggest value="d2"/>
    <suggest value="d3"/>


(drkm)[5] ~/xslt/tests$ cat spell-check.xsl

  <xsl:output method="text"/>

  <xsl:template match="spellchecker">
    <xsl:apply-templates select="word[1]"/>

  <xsl:template match="word">
    <xsl:param name="line" select="''"/>
    <xsl:apply-templates select="suggest">
      <xsl:with-param name="line" select="$line"/>

  <xsl:template match="suggest | word[empty(*)]">
    <xsl:param name="line" select="''"/>
    <xsl:variable name="next-word" select="
        | following-sibling::word[1]"/>
    <xsl:variable name="new-line" select="
        concat($line, ' ', @value)"/>
      <xsl:when test="empty($next-word)">
        <xsl:value-of select="$new-line"/>
        <xsl:apply-templates select="$next-word">
          <xsl:with-param name="line" select="$new-line"/>


(drkm)[6] ~/xslt/tests$ saxon spell-check.xml spell-check.xsl
 a1 b c1 d1
 a1 b c1 d2
 a1 b c1 d3
 a1 b c2 d1
 a1 b c2 d2
 a1 b c2 d3
 a1 b c3 d1
 a1 b c3 d2
 a1 b c3 d3
 a2 b c1 d1
 a2 b c1 d2
 a2 b c1 d3
 a2 b c2 d1
 a2 b c2 d2
 a2 b c2 d3
 a2 b c3 d1
 a2 b c3 d2
 a2 b c3 d3

(drkm)[7] ~/xslt/tests$

  I think that would help you, if I understood corectly your problem.



Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 

Current Thread


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.
First Name
Last Name
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.