[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: help XML
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|