RE: [xsl] Sorting Question: Muenchian method? Substring in Key?

Subject: RE: [xsl] Sorting Question: Muenchian method? Substring in Key?
From: "Robert Koberg" <rob@xxxxxxxxxx>
Date: Fri, 27 Sep 2002 09:22:41 -0700
Oops...

That should have been:

not(substring(.,1,1) = substring(preceding-sibling::topic,1,1))

-Rob

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Robert Koberg
> Sent: Friday, September 27, 2002 9:06 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Sorting Question: Muenchian method? Substring in Key?
> 
> 
> Hi,
> 
> try passing it this way:
> 
> <xsl:template match="topics">
>   <div class="topics">
>     <xsl:apply-templates select="topics/topic">
>       <xsl:sort select="."/>
>     </xsl:apply-templates>
>   </div>
> </xsl:template>
> 
> <xsl:template match="topic">
>   <xsl:variable name="previndex" select="position()-1"/>
>   <xsl:if test="not(substring(.,1,1) =
> substring(/topics/topic[$previndex],1,1))">
>     <div class="topicTitle"><xsl:value-of select="substring(.,1,1)"/></div>
>   </xsl:if>
>   <div class="topic"><xsl:value-of select="."/></div>
> </xsl:template>
> 
> best,
> -Rob
> 
> 
> 
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Thomas_M
> > Sent: Friday, September 27, 2002 8:27 AM
> > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> > Subject: [xsl] Sorting Question: Muenchian method? Substring in Key?
> >
> >
> > Hello. This is my first XSLT project. I'm having trouble with grouping
> > sorted items (seems to be a common theme). I have a XML file like this
> > (simplified):
> >
> > <topics>
> >   <topic>Anteater</topic>
> >   <topic>Aardvark</topic>
> >   <topic>Beetle, Smaller European Elm Bark</topic>
> >   <topic>Beetle, American Burying</topic>
> >   <topic>Chimpanzee</topic>
> > </topics>
> >
> > I would like the output to be sorted and grouped, with each group getting a
> > heading:
> >
> > A
> > Aardvark
> > Anteater
> >
> > B
> > Beetle, American Burying
> > Beetle, Smaller European Elm Bark
> >
> > C
> > Chimpanzee
> >
> > The corresponding part of my XSL is below.
> >
> >   <xsl:template match="topics">
> >    <table border="1">
> >       <xsl:for-each select="topic">
> >         <xsl:sort select="."/>
> >         <xsl:variable name="previndex" select="position()-1"/>
> >         <xsl:if test="not(substring(.,1,1)
> >                       = substring(/topics/topic[$previndex],1,1))">
> > 		<tr><th><xsl:value-of select="substring(.,1,1)"/></th></tr>
> >
> >         </xsl:if>
> >             <tr>
> >               <td><xsl:value-of select="."/></td>
> >             </tr>
> >       </xsl:for-each>
> >     </table>
> >   </xsl:template>
> >
> > As you can see, I'm comparing an element in a sorted node-set with a
> > document-order node-set. This works only if the XML is pre-sorted. Is there
> > a way to create the sorted node-set first, so that I can both traverse and
> > use it in my test?
> >
> > I have seen a few examples of the Muenchian method, and it would seem this
> > is another (perhaps better) way solve my problem. However, I've tried
> > several times to implement it and can't seem to get it right (can you use a
> > substring in a key?)
> >
> > Thanks for any insight,
> >
> > - Mark.
> >
> > --
> > Mark Thomas                       |_|
> > Internet Systems Architect        -+-
> > User Technology Associates, Inc.   |
> > Thomas_M@xxxxxxx                  /-\
> >
> >
> >
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread