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

xsl:if test = empty string, returns true

Subject: xsl:if test = empty string, returns true
From: Jorge <chocolate.camera@xxxxxxxxx>
Date: Sun, 13 May 2012 22:03:57 +0200
 xsl:if test = empty string
According to http://www.w3.org/TR/xpath/#section-Boolean-Functions:

> The boolean function converts [] a string to true if and only if its length
is non-zero.

My XSLT 2.0 stylesheet has an xsl:if element testing a function that seems to
be returning a string of length zero, and yet the test evaluates to true. I am
processing the stylesheet with Saxon-HE with this command line:

> java -jar saxon/saxon9he.jar -it:main -xsl:./test.xsl

This is the stylesheet `test.xsl`:

> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 xmlns:me="null">
> 	<xsl:variable name="PLIST" select="'./test.plist'"/>
> 	<!-- Load external plist into variable -->
> 	<xsl:variable name="metadata" select="document(iri-to-uri($PLIST))"/>
> 	<!-- Function to fetch value of a key-string pair in plist -->
> 	<xsl:function name="me:metadata">
> 		<xsl:param name="label"/>
> 		<xsl:value-of
> 	</xsl:function>
> 	<xsl:output method="text" encoding="UTF-8"/>
> 	<xsl:template name="main" exclude-result-prefixes="me">
> 		<xsl:choose>
> 			<xsl:when test="me:metadata('testkey')">
> testkey = "<xsl:value-of select="me:metadata('testkey')"/>"
> testkey's length = <xsl:value-of
> 			</xsl:when>
> 			<xsl:otherwise>
> 				"testkey" is empty or does not exist.
> 			</xsl:otherwise>
> 		</xsl:choose>
> 	</xsl:template>
> </xsl:stylesheet>

As you can see, the stylesheet imports a plist (XML) file, `test.plist`, into
a variable, and calls the function me:metadata() which returns the value of a
certain key in that plist as a string. The plist in question, which I quote
below, does contain the requested key, but its value is blank, and hence the
function should be returning a string of zero length (which is confirmed by
running the function again inside string-length()).

> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
> <plist version="1.0">
> <dict>
> 	<key>testkey</key>
> 	<string></string>
> </dict>
> </plist>

Any idea why the test evaluates to true?

Please note that I am not wondering whether the way I wrote the stylesheet is
the most appropriate way to do what it is supposed to do, but why the test is
evaluating to true.

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.