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

Re: Seek an XPath 2.0 expression that handles an empty

Subject: Re: Seek an XPath 2.0 expression that handles an empty text field, regardless of how it's represented in XML
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Sep 2016 22:12:52 -0000
Re:  Seek an XPath 2.0 expression that handles an empty
On Thu, Sep 22, 2016 at 04:01:39PM -0000, G. Ken Holman g.ken.holman@xxxxxxxxx scripsit:
> At 2016-09-22 15:55 +0000, Costello, Roger L. costello@xxxxxxxxx wrote:
> > I want an XPath 2.0 expression that outputs "do action" if the B field
> > is empty, regardless of which of the two XML representations is used.
> > This XPath expression seems to work:
> > 
> > if (not(B) or B eq '') then "do action" else "no action"
> 
> This gives you the same result:
> 
> if (not(string(B))) then "do action" else "no action"

You could also use

if (not(boolean(B))) then "do action" else "no action"

which exploits empty strings being false().

Though that's definitely the sort of logic that should get a comment
explaining to your future self what you're going.

-- Graydon

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.