xsl-list
[Top] [All Lists]

RE: filter based on parameter, not getting it.

2002-09-20 15:41:57
Hi Will,

Not sure if this is what you want - but try...

== XSL ==========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:param name="filterparam"/>
<xsl:variable name="ifilter"
select="//person[string-length($filterparam) = 0] |
//person[string-length($filterparam) != 0][cat = $filterparam]"/>

<xsl:template match="/">
  <table>
        <xsl:for-each select="$ifilter">
        <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>
  </table>
</xsl:template>

</xsl:stylesheet>
== end of XSL ===================================

Hope this helps
Marrow 
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator



-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Carter, Will
Sent: 20 September 2002 23:21
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] filter based on parameter, not getting it.

okay, here is my attempt...not working...very frustrating.

my error: Can not convert #STRING to a NodeList!

<xsl:param name="filterparam"/>

<!-- try to take the if condition out of the test template -->
<xsl:template match="/">
<xsl:choose>
        <xsl:when test="string-length($filterparam) = 0">
                <xsl:call-template name="test">
                        <!-- trying to call the test template with no
filter -->
                        <xsl:with-param name="filter"
select="//person"></xsl:with-param>
                </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
                <xsl:call-template name="test">
                        <!-- trying to call the test template with the
filterparam as the filter -->
                        <xsl:with-param name="filter"
select="//person[cat = $filterparam]"></xsl:with-param>
                </xsl:call-template>
        </xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="test" match="/">
<xsl:param name="filter"/>
<xsl:variable name="filter" select="$filter"/>
<table>
        <xsl:for-each 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>
</table>
</xsl:template>





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