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

Subject: Re: [xsl] comparing sequences that contain more than one of the same item
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Fri, 22 Feb 2008 09:12:57 -0500
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@xxxxxxxxxx> 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

Current Thread