Re: [xsl] Sorting + unique copy problem

Subject: Re: [xsl] Sorting + unique copy problem
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Thu, 8 Nov 2001 15:22:34 -0500
Jeni,

> I think it only does because the KeyWords are actually defined in
> alphabetical order anyway :)

Ah, yes, of course...

Well, here's my solution - it works with your scrambled keywords too.  I
like to turn unique list into a variable by itself. That way I can use it
for other things with it later on:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method='html'/>

<xsl:key name="kw" match="KeyWord" use="."/>
<xsl:variable name='keywords'
    select='/Filmlist/Film/KeyWord
       [generate-id(.)=generate-id(key("kw",.)[1])]'/>

<xsl:template match="/">
    <form action="process_user.jsp" TARGET="result" method="get">
       <select type="text" name="kw" size="20" maxlength="125">
          <option value="empty"/>
          <xsl:for-each select="$keywords">
              <xsl:sort select='.'/>
           <option value="{.}"><xsl:value-of select="."/></option>
       </xsl:for-each>
        </select>
    </form>
</xsl:template>

</xsl:stylesheet>


BTW, I just ordered your book ... hoping for great things from it!

Cheers,

Tom


> Tom,
>
> > After I made that fix, the select box does have the keywords sorted
> > alphabetically as you want.
>
> I think it only does because the KeyWords are actually defined in
> alphabetical order anyway :) Try it with:
>
> <Filmlist>
>     <Film>
>         <KeyWord>Keyword3</KeyWord>
>         <KeyWord>Keyword7</KeyWord>
>     </Film>
>     <Film>
>         <KeyWord>Keyword5</KeyWord>
>         <KeyWord>Keyword1</KeyWord>
>         <KeyWord>Keyword3</KeyWord>
>         <KeyWord>Keyword6</KeyWord>
>     </Film>
>     <Film>
>         <KeyWord>Keyword1</KeyWord>
>         <KeyWord>Keyword2</KeyWord>
>         <KeyWord>Keyword3</KeyWord>
>         <KeyWord>Keyword4</KeyWord>
>     </Film>
> </Filmlist>
>
> Cheers,
>
> Jeni
>



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


Current Thread