Hi Thomas,

Yes, generic XSLT questions are best asked on the Mulberry list. Not only
will you get a faster response there, but you will likely get multiple
responses, which may help you figure out the best way to do something.

In XSLT 1.0, any xsl:variable element that contains content creates a
result tree fragment, and, in XPath 1.0, you cannot use if/else logic in
expressions.  On the other hand, there are a surprising number of tricks to
get XPath 1.0 to do what you want, so you should definitely post your
questions to the Mulberry list.

As a last result, you can always create a result tree fragment, and compare
the result as a string:

   <xsl:variable name="boolean_test">
             <xsl:choose>
                         <!-- imagine a more rigorous test, here... -->
                         <xsl:when test="true()"><xsl:value-of
   select="true()"/></xsl:when>
                         <xsl:otherwise><xsl:value-of
   select="false()"/></xsl:otherwise>
             </xsl:choose>
   </xsl:variable>

   <xsl:if test="$boolean_test = string(true())">
   ...

Dave



|---------+--------------------------->
|         |           "Thomas F.      |
|         |           O'Connell"      |
|         |           <[EMAIL PROTECTED]|
|         |           com>            |
|         |                           |
|         |           06/23/2003 10:07|
|         |           AM              |
|---------+--------------------------->
  
>---------------------------------------------------------------------------------------------------------------|
  |                                                                             
                                  |
  |        To:      xalan-c-users@xml.apache.org                                
                                  |
  |        cc:      (bcc: David N Bertoni/Cambridge/IBM)                        
                                  |
  |        Subject: Re: boolean variable evaluation                             
                                  |
  
>---------------------------------------------------------------------------------------------------------------|



Thanks to all who pointed out the subtleties of the difference between
getting back a result tree fragment rather than true boolean output.

So here's my next question:

Is there a way to achieve the same effect (i.e., not getting a result
tree fragment) if you want to set a variable conditionally?

For example, suppose I wanted to do something like this:

<xsl:variable name="boolean_test">
             <xsl:choose>
                         <!-- imagine a more rigorous test, here... -->
                         <xsl:when test="true()">
                                     <!-- somehow set boolean test to
true() -->
                         </xsl:when>
                         <xsl:otherwise>
                                     <!-- somehow set boolean_test to
false() -->
                         </xsl:otherwise>
             </xsl:choose>
</xsl:variable>

Currently, I'm setting the value of the variable to the test itself, but
I can foresee cases where one might want to include a more complicated
XSL structure in the body of a variable tag such that directly using a
select isn't sufficient. In such a case, will the result always be a
result tree fragment?

If this is better posted to an XSL(T) list, I can redirect it. But it's
following up on an existing thread, so I figured I'd give it a shot.

Thanks!

-tfo

On Fri, 2003-06-20 at 16:54, Thomas F. O'Connell wrote:
> I've got a question about Xalan's behavior regarding setting booleans to
> explicit functions.
>
> If I've got a stylesheet that includes the following:
>
> <xsl:variable name="boolean_test">
>            <xsl:value-of select="false()" />
> </xsl:variable>
>
> And I then use it in this sort of expression:
>
> <xsl:if test="boolean_test">
>            <message>This is not what I was expecting</message>
> </xsl:if>
>
> I'll get the message every time. Is that correct and expected behavior,
> or is it a bug?
>
> -tfo



Reply via email to