[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: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 14 May 2012 15:52:31 +0100
Re:  xsl:if test = empty string
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::node()[1]/text())"/>

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

Current Thread


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.
First Name
Last Name
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.