This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: variable in filter doesn't work??
- From: "Passin,Thomas B. (Tom)" <tpassin at mitretek dot org>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 20 Sep 2002 13:33:59 -0400
- Subject: RE: [xsl] variable in filter doesn't work??
- Reply-to: xsl-list at lists dot mulberrytech dot com
[Carter, Will]
>
> why doesn't this work?
> -----------------------
> <xsl:variable name="filter" select='"cat =
> 'zoro'"'/> <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='zoro'"]'>
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