Hi Folks, This is a continuation of my previous post… I showed two XML representations of an empty field in a tab-delimited file. One representation omitted the element: <Row> Of course, I want to do something with the XML. Specifically, I want an XPath expression that will output “do action” if the field is empty. Since the empty field is represented by no element,
this XPath expression will work:
if (not(B)) then "do action" else "no action" Read as: If there does not exist a B element then … The second way to represent an empty field is with an empty element: <Row> The XPath expression shown above will
not work with the second XML representation. This XPath expression will work:
if (B eq '
') then "do action" else "no action" But it will
not work with the first XML representation. So this is the key question:
Is there an XPath expression that will correctly What a beautiful question! The answer to that question is yes, if we confine ourselves to the two XML representations described above (which seems to be the most typical).
Any of the following XPath expressions will handle both XML representations. David Sewell provided this solution:
if (not(B) or normalize-space(B) eq '') then "do action" else "no action" Ken Holman provided this solution:
if (not(string(B))) then "do action" else "no action" David Carlisle provided this solution:
if (B/node()) "d" else "n", "o action" /Roger |