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

Re: xsl filter problem

Subject: Re: xsl filter problem
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 26 Dec 2002 04:05:37 -0700 (MST)
xsl filter
Yuval wrote:
> My xml looks like this :
> 
> <customers>
> 	<customer>
> 		<city>a</city>
> 		<name>Jhon<name>
> 	</customer>
> 	<customer>
> 		<city>b</city>
> 		<name>Don<name>
> 	</customer>
> 	<customer>
> 		<city>c</city>
> 		<name>Ron<name>
> 	</customer>
> </customers>
> 
> The data is to presented in a table and I want to filter it according to
> the "city" - meaning I have 4 options :
> 1.a
> 2.b
> 3.c
> 4.all the cities = no filter
> 
> Im using a html select box to let the user choose which city to filter
> and the first option is "all cities".for this parameter I give the value
> *.
> 
> The xsl looks like this :
> 
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> 	<xsl:output method="xml" encoding="windows-1255" />
> 	
> 	<xsl:param name="city"  />
> 		
> 	<xsl:template match="/">
> 		<customers>		
> 			<xsl:for-each
> select="customers/customer[city=$city]">
> 				<customer>
> 					<xsl:for-each select="*">
> 						<xsl:element
> name='{name()}'>
> 							<xsl:value-of
> select="." />
> 						</xsl:element>
> 					</xsl:for-each>
> 				</customer>
> 			</xsl:for-each>
> 		
> 		</customers>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> When choosing "all cities" - the result is an empty table instead of the
> list of all cities with the customers names.
> I tried to giva the param "city" a diect value of "*" or " '*' " and it
> still didn't work.
> How can I pass a value to this param which will act like : <xsl:for-each
> select="customers/customer[city=*]"> ??

Don't forget to quote the *.

It looks to me like your conditions are as follows:

If $city = '*', you want all customer elements.
If $city != '*', you want all customer elements for which child::city = $city.

Rephrase this into a test for each customer element:

You want all customer elements for which:
  $city = '*' is true
  or
  child::city = $city

The answer, unless I've overlooked something, is:

customers/customer[$city='*' or city=$city]

Another option is to let $city be an empty string to indicate "all cities".
Then you'd use:

customers/customer[not($city) or city=$city]

Also note that instead of <xsl:element name="{name()}">...</xsl:element>
you can use <xsl:copy>...</xsl:copy>.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • xsl filter problem
    • Yuval - Wed, 25 Dec 2002 18:50:02 -0500 (EST)
      • Mike Brown - Wed, 25 Dec 2002 19:59:21 -0500 (EST)
        • Yuval - Thu, 26 Dec 2002 05:10:00 -0500 (EST)
          • Mike Brown - Thu, 26 Dec 2002 06:05:23 -0500 (EST) <=

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
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.