xsl-list
[Top] [All Lists]

Re: [xsl] comparing sequences that contain more than one of the same item

2008-02-22 07:13:33
Oh, sorry. Read too fast.

Dmitry probably has this handled in FXSL (or will :) )

best,
-Rob


On Fri, 2008-02-22 at 14:08 +0000, Andrew Welch wrote:
The goal is to give you all possible words that can be made out of a given 
word.

So for "farmer" you get:

framer
armer
farer
frame
rearm
fame
fare
...

So I'm looking for a comparison that checks if a word can be made out
of the letters of another word.

The recursive function that I wrote 10 mins ago looks like this, where
$searchWord would be the codepoints for "farmer", and $wordListWord
would be any word from my list of words:

<xsl:function name="f:checkWord" as="xs:boolean">
    <xsl:param name="searchWord" as="xs:integer*"/>
    <xsl:param name="wordListWord" as="xs:integer*"/>

    <xsl:variable name="firstChar" select="$wordListWord[1]" 
as="xs:integer?"/>

    <xsl:choose>
        <xsl:when test="empty($wordListWord)">
            <xsl:sequence select="true()"/>
        </xsl:when>
        <xsl:when test="empty($searchWord)">
            <xsl:sequence select="false()"/>
        </xsl:when>
        <xsl:when test="$firstChar = $searchWord">
            <xsl:sequence select="f:checkWord(remove($searchWord,
index-of($searchWord, $firstChar)[1]), remove($wordListWord, 1))"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:sequence select="false()"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:function>





On 22/02/2008, Robert Koberg <rob(_at_)koberg(_dot_)com> wrote:

 contains(str1, str2)

 ?


 On Fri, 2008-02-22 at 13:57 +0000, Andrew Welch wrote:
 > A bit of a Friday challenge...
 >
 > Is it possible to compare to sequences such that items in the sequence
 > are consumed after the comparison?
 >
 > For example, I want to compare two words to see if one is a subset of 
the other.
 >
 > "farmer" and "frame"
 >
 > If you do:
 >
 > string-to-codepoints('farmer')[not(. = string-to-codepoints('frame'))]
 >
 > the result is empty because the two r's in farmer are both being
 > compared to the single r in frame.
 >
 > Currently I've a got a recursive function that removes each letter
 > after a match, but I'm wondering if there's a one-liner or some other
 > set based approach?
 >
 >
 > thanks



--~------------------------------------------------------------------
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
 To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
 or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
 --~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--