Re: [xsl] xsl:if with params

Subject: Re: [xsl] xsl:if with params
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 24 Sep 2004 15:12:40 +0100
  So, when i'm making

        <xsl:if test="$main">

  what am i saying in english?

You are saying if the boolean value of $main is true() then do something.


What probably is confusing you is that pretty much everything in Xpath
has a boolean value. Or to put it another way, will silently be coerced
to boolean if it has another type.

Node sets are true() if they are non-empty,

  <xsl:param name="main" select="somevalue"/>

so that has set the default value of $main to be the node set selected
by the xpath somevalue when the current node is the root  of the
document. So if somevalue is not the name of the top level element, this
is an empty node set so $main will act as false() in a boolean test.



    stylesheet.setParameter("main", "ok");

here you have set $main to be the string "OK" strings are coerced to
true() if they are non empty and false() if they are "" so "ok" like any
non empty string will test as true()

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread