xsl-list
[Top] [All Lists]

Re: [xsl] Switching off a filter by parameter

2006-11-13 10:47:55
Guy wrote:
I have the following snippet of XSL to filter a book collection by category:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:param name="categor"/>
  <xsl:template match="/">
      <xsl:for-each select="books/book">
        <xsl:if test="category=$categor">
          <!-- Show info... -->
        </xsl:if>
      </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

My question: If the categor param is zero length (i.e. no filter) then how
do I test for this and allow all books through? In other words I would like
the commented code in the snippet above to be executed if the categor param
is not filled in.

Thanks!

Hi,

Specify a default value for the parameter:
<xsl:param name="categor" select="''"/>

And test for it:
<xsl:if test="$categor='' or category=$categor">

        # r

-- 
Ronan Klyne
Business Collaborator Developer
Tel: +44 (0)870 163 2555
ronan(_dot_)klyne(_at_)groupbc(_dot_)com
www.groupbc.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>