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

RE: variable in filter doesn't work??

Subject: RE: variable in filter doesn't work??
From: "Passin,Thomas B. (Tom)" <tpassin@xxxxxxxxxxxx>
Date: Fri, 20 Sep 2002 13:33:59 -0400
xsl filter variable
[Carter, Will]
> 
> why doesn't this work?
> -----------------------
> <xsl:variable name="filter" select='"cat = 
> &apos;zoro&apos;"'/> <xsl:value-of select="$filter"/>
> 	<tr>
> 		<td><xsl:value-of select="cat"/></td>
> 		<td><xsl:value-of select="dog"/></td>
> 		<td><xsl:value-of select="fish"/></td>
> 	</tr>
> </xsl:for-each>

Aside from the fact that you have omitted the contents on the
xsl:for-each start tag so we cannot be sure what you wrote, you cannot
use a variable as a path expression.  You are probably saying the
equivalent of

<xsl:for-each select='person["cat=&apos;zoro&apos;"]'>

This does not do any filtering because the predicate has to be either a
number (to select a particular node by its position) or an expression.
An expression gets evaluated as a boolean.  A non-empty string evaluates
to "true", so your statement is equivalent to

<xsl:for-each select='person[true]'>

This will select all person nodes as you have seen.

You could write

<xsl:variable name='filter' select='"zoro"'/>
<xsl:for-each select='person[cat=$filter]'>

This is not quite what you are after,it seems.  You could get the effect
you are trying for this way:

<xsl:variable name='filter-element' select='"cat"'/>
<xsl:variable name='filter-value' select='"zoro"'/>
<xsl:for-each select="person[*[name()=$filter-element and
text()=$filter-value]]">

Cheers,

Tom P

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


Current Thread

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.