OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] help XML

[ Lists Home | Date Index | Thread Index ]

Binh Thang wrote:
> I don't receive the error message anymore but still it doesn't sort. 
> Below I copied a piece of my xml file. I would like to sort on name of 
> the restaurant. Can you pls. help?
> <xsl:template match="/">
>   <html>
>   <body [snip]>
>   <h2>My Restaurants Guide</h2>
>    <xsl:apply-templates />
>   </body>
>   </html>
> </xsl:template>
> <xsl:template match="restaurant">
> <p>   
>  <xsl:apply-templates>
> <xsl:sort select="name"/>
> </xsl:apply-templates>
> </p>  
> </xsl:template>
> <xsl:template match="name">

I miss the XML.
You seem to be under the impression the xsl:sort instruction
should appear in the template which matches the element you
want to sort. THis is not the case, the xsl:sort must appear
in the xsl:apply-templates (or xsl:foreach) which selects the
list of elements you want to sort.

If your source XML is like
then try this
  <xsl:template match="/">
    <h2>My Restaurants Guide</h2>
      <xsl:apply-templates select="restaurants/restaurant">
        <xsl:sort select="name"/>

BTW questions regarding XSL are best asked on the XSL list:
THere's also a FFAQ reachable from the page above which has
lots of sample code, some of which is relevant for your question.



News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS