[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2007-01-28 23:54 -0500, M. Casey wrote:
Welcome!
This sorts the one word within each entry that fits the criteria and returns the result in the order of the entries:
This sorts all of the words if any of the entries fit the criteria:
You are not selecting only the ones meeting your criteria and then sorting those ... please see the example below.
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
<xsl:output method="text"/>
T:\ftemp>
Re: [xsl] Newbie needs help with sorting a filtered list
Subject: Re: [xsl] Newbie needs help with sorting a filtered list From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 29 Jan 2007 00:40:09 -0500 |
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;
apple
banana
orange
is the result I want.
Here's the XML: ... This gives me the correct items, but not in alphabetical order:
<xsl:param name="param1"/> <xsl:param name="param2"/>
<xsl:template match="catalog/entry"> <xsl:if test="category[@type=$param1] and category[@subcat=$param2]"> <xsl:for-each select="word">
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:
orange apple banana
This one gives me an alphabetized list, but of all the items, not just the ones that match the params:
<xsl:template match="catalog">
<xsl:if test="entry/category[@type=$param1] and entry/category[@subcat=$param2]">
<xsl:for-each select="entry/word">
This sorts all of the words if any of the entries fit the criteria:
Returns this:
apple banana endive kale orange spinach
What am I doing wrong,
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Newbie needs help with so, Michael Kay | Thread | [xsl] xinclude in xslt 2.0 now avai, Erik Wilde |
[xsl] Newbie needs help with sortin, M. Casey | Date | Re: [xsl] Newbie needs help with so, James A. Robinson |
Month |