Re: [xsl] Re: Capturing/testing results of a boolean expression.

Subject: Re: [xsl] Re: Capturing/testing results of a boolean expression.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 02 Aug 2002 18:46:33 -0400
Ed,

At 05:59 PM 8/2/2002, you wrote:
Maybe details are called for, because as I gnaw at this problem and read
archives I realize the trick might be to establish an expression which
returns a "boolean" as opposed to an expression which returns a
"results-tree-fragment".

Quite right. This is a tricky subtlety in declaring variables, that these aren't the same thing.


I have a variable which will have a string value.  I wish to compare
that string value to another string value (which happens to be a literal
value).  I've done this directly in a xsl:if or xsl:when before, but now
I'm trying to capture the results of the expression in a variable.

<xsl:variable name="X" ..../>

<xsl:variable name="flag" select="$X = 'literal-string-value'" />

Is there a way to do this that returns a 'boolean' and not a
'results-tree-fragment'?

The way you gave should do precisely that. The select="$X = 'literal-string-value'" will return a Boolean and bind it to the variable. Whereas


<xsl:variable name="flag">
  <xsl:value-of select="$X = 'literal-string-value'" />
</xsl:variable>

will take the Boolean, turn it into a string, and put it into an RTF.

Is there a way to take a 'results-tree-fragment' which has the value
"true" or "false" and turn it back into the equivalent 'boolean' value?

Sure:


<xsl:variable name="flag" select="$rtf = 'true'"/> will bind $flag to Boolean true() only if the string value of $rtf is 'true'; otherwise it'll be false().

(true() and false() are functions that will return the Boolean true and false values respectively. They too may be useful to you.)

But any time you do <xsl:value-of select="$flag"/> you are coercing the Boolean back into a string, since that's what value-of does.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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



Current Thread