[xquery-talk] How to handle empty sequence?

Ed O'Neill tenacious61 at sbcglobal.net
Thu Jan 20 00:27:17 PST 2005

Mr. Kay,

Thank you. It took me a while to realize the last "for" loop I had, 
could be completely replaced by your suggestion, pulling the first 
element of the sequence directly. It works perfectly.

-----Original Message-----
From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com]On Behalf
Of Michael Kay
Sent: Tuesday, January 18, 2005 1:32 AM
To: 'Ed O'Neill'; talk at xquery.com
Subject: RE: [xquery-talk] How to handle empty sequence?

 >             let $version := ($release3/version)
 >             return
 >               <td>
 >               <CENTER>
 >               {
 >                if (string-length(string($version/node())) =
 > 0) then "NA"
 >                else $version/node()
 >                }
 >             </CENTER>
 >             </td>

 > This query works fine if all applications have a version in each
 > environment. The problem is when I have an application that
 > does not have
 > any versions released to a particular env. .When this occurs, the
 > $sorted_releases sequence will be empty, so I never get to
 > "for $release3"
 > return to generate the necessary table element (which would be blank).

Yes, you can't do $version/node() if $version is a string. But why are you
doing $version/node() anyway? If the input is <version>13<!--I
think--></version>, this will fail because the version element has two child
nodes, and string() must take a singleton as its argument. Better to take
the string value of the element node itself.

I would do

let $version = string(($release3/version, "NA")[1])

talk at xquery.com

More information about the talk mailing list