[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Newbie needs help with sorting a filtered list
At 2007-01-28 23:54 -0500, M. Casey wrote:
I'm an absolute newbie at XSL. Welcome! I have an ASP form which is passing two values to my xsl -- let's say for this example "food" and "fruit". I need an alphabetized list of all items that match those criteria. So; This sorts the one word within each entry that fits the criteria and returns the result in the order of the entries: Returns this list: This sorts all of the words if any of the entries fit the criteria: Returns this: You are not selecting only the ones meeting your criteria and then sorting those ... please see the example below. and why do these two versions, which to my rank amateur brain look like they should be the same, return such different results? Because you are not considering the position of the current node and the selection of the current node list for the sort. I hope the answer below helps. . . . . . . . . . Ken T:\ftemp>type casey.xml <catalog> <entry> <word>orange</word> <category type="food" subcat="fruit"/> <info> <serving_size>...</serving_size> <preparation>...</preparation> </info> </entry> <entry> <word>spinach</word> <category type="food" subcat="vegetable"/> <info> <serving_size>...</serving_size> <preparation>...</preparation> </info> </entry> <entry> <word>apple</word> <category type="food" subcat="fruit"/> <info> <serving_size>...</serving_size> <preparation>...</preparation> </info> </entry> <entry> <word>kale</word> <category type="food" subcat="vegetable"/> <info> <serving_size>...</serving_size> <preparation>...</preparation> </info> </entry> <entry> <word>endive</word> <category type="food" subcat="vegetable"/> <info> <serving_size>...</serving_size> <preparation>...</preparation> </info> </entry> <entry> <word>banana</word> <category type="food" subcat="fruit"/> <info> <serving_size>...</serving_size> <preparation>...</preparation> </info> </entry> </catalog> T:\ftemp>type casey.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:param name="param1"/> <xsl:param name="param2"/> <xsl:template match="/"> param1=<xsl:value-of select="$param1"/> param2=<xsl:value-of select="$param2"/> <xsl:text> </xsl:text> <xsl:for-each select="catalog/entry[category/@type=$param1 and category/@subcat=$param2]"> <xsl:sort select="word"/> <xsl:apply-templates select="word"/> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> T:\ftemp>xslt casey.xml casey.xsl con param1=food param2=fruit param1=food param2=fruit apple banana orange T:\ftemp> -- World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
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
|