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 |
I'm an absolute newbie at XSL.
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">
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">
Returns this:
apple banana endive kale orange spinach
What am I doing wrong,
and why do these two versions, which to my rank amateur brain look like they should be the same, return such different results?
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: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
-- 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 |