xsl-list
[Top] [All Lists]

[xsl] Seek an XPath 2.0 expression that handles an empty text field, regardless of how it's represented in XML

2016-09-22 10:55:07
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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>