[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: "Sewell, David R. (drs2n) dsewell@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Sep 2016 15:58:59 -0000
Re:  Seek an XPath 2.0 expression that handles an empty
The XPath you have is what I would probably use, only if there's any chance of creating pseudo-empty elements with whitespace only I would use normalize-space:

if (not(B) or normalize-space(B) eq '') then "do action" else "no action"

David

On Thu, 22 Sep 2016, Costello, Roger L. costello@xxxxxxxxx wrote:

Hi Folks,

I have a tab-delimited text file. Here is one row of the file:

A 	B 	C
foo		bar

The value in field B is optional. In this particular row there is no value for B so it is empty.

I could represent the text file in XML by creating an element for each field and then putting a wrapper element around the elements. For an empty field I could represent that by omitting the element. So here is one way to represent the row:

<Row>
   <A>foo</A>
   <C>bar</C>
</Row>

Notice that I omitted the <B> element because the B field is empty.

Alternatively, I could represent an empty field with an empty element:

<Row>
   <A>foo</A>
   <B/>
   <C>bar</C>
</Row>

Notice the empty <B> element.

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"

Is there a better (simpler, more efficient, more future-proof) XPath 2.0 expression?

/Roger



-- David Sewell Manager of Digital Initiatives The University of Virginia Press Email: dsewell@xxxxxxxxxxxx Tel: +1 434 924 9973 Web: http://www.upress.virginia.edu/rotunda

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.