[xquery-talk] Elegant form of testing for () and ''

David Lee dlee at calldei.com
Fri Mar 4 12:10:43 PST 2011

I run into this problem frequently and it tends to bite me in production
months later, not in unit testing.

Suppose I have a string which rarely can be () but more often ''


I've used this test


declare function local:getname( $e ) as xs:string


       let $name := $e/name/string()


if( $name ne '' ) then $name else "<untitled>"



But a few months later it ends up in 1 case being () and this function
crashes because () cant be coerced to xs:string



So I augment it to 


if( exists($name) and $name ne '' ) then $name else "<untitled>"



But this pattern seems so common, is there a more elegant or concise way of
testing for both () and '' ?

( I have the same problem with NUL values in SQL world , and null values in
java ... but thats another problem ... xquery is (N+1)G so it should be
easier right ?






David A. Lee

 <mailto:dlee at calldei.com> dlee at calldei.com

 <http://www.xmlsh.org> http://www.xmlsh.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20110304/08ca3238/attachment.htm

More information about the talk mailing list