[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: help XML


xsl foreach example
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
  <restaurants>
    <restaurant>
       <name>Foo</name>
      ...
then try this
  <xsl:template match="/">
    <html>
    <body>
    <h2>My Restaurants Guide</h2>
      <xsl:apply-templates select="restaurants/restaurant">
        <xsl:sort select="name"/>
      </xsl:apply-templates>
    </body>
    </html>
  </xsl:template>

BTW questions regarding XSL are best asked on the XSL list:
  http://www.mulberrytech.com/xsl/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.

J.Pietschmann

  • References:

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.