[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:if test = empty string, returns true

Subject: Re: xsl:if test = empty string, returns true
From: Jorge <chocolate.camera@xxxxxxxxx>
Date: Tue, 15 May 2012 16:02:51 +0200
Re:  xsl:if test = empty string
Thank you all so much for all the rather granular explanations.

One thing I tried unsuccessfully is finding a way to unequivocally see what
was coming out of the function, and what xsl:if was testing. Up until know I
have only played with XSLT using a general-purpose text editor and running
Saxon a zillion times.

When I started guessing that I was not quite understanding what exactly the
function was returning, I tried to find a visual debugger that could describe
it to me. I tried Oxygen Developer's demo, but could not find a way to do that
(i.e. showing me what exactly xsl:if was testing).

Any heads up on how or with what tool I could have noticed I was getting a
node and not a string (besides learning XSLT properly)? I use Mac OS X 10.7 so
I am limited by what works on this platform.

--
Jorge


El 14/05/2012, a las 16:52, Michael Kay <mike@xxxxxxxxxxxx> escribis:

> You're not alone in finding this confusing. Some highly experienced people
have given you incorrect information on this thread.
>
>   <!-- Function to fetch value of a key-string pair in plist -->
>   <xsl:function name="me:metadata">
>       <xsl:param name="label"/>
>       <xsl:value-of
select="normalize-space($metadata/plist/dict/key[text()=$label]/following::no
de()[1]/text())"/>
>   </xsl:function>
>
> This function is NOT returning a string, and it is NOT returning a document
node as some have suggested. It is returning a text node, because that is
what<xsl:value-of>  creates. Unlike xsl:variable, xsl:function does not wrap
the text node in a document node; in the absence of an "as" attribute on
xsl:function, it returns the text node unchanged.
>
> Although I always recommend using an "as" attribute on xsl:function and
xsl:param to make it clear what the inputs and output to the function are
expected to be, the simplest fix to this function is to change<xsl:value-of>
to<xsl:sequence>. It's a common mistake to use xsl:value-of when there is no
intention or need to create a text node. The normal default way of returning a
result from a function should be to use xsl:sequence.
>
>> Any idea why the test evaluates to true?
>
> The effective boolean value of a node is always true. In fact, Saxon can
work out that this function will always return a text node, and it will
probably therefore decide that the EBV of the function call is true without
even calling the function.
>
> Michael Kay
> Saxonica

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.