0

how to make xpath 1.0 behave like if value is empty - return string "empty"

if I have an XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<query systemEnvironmentCode="UAT">
    <trxid>107</trxid>
    <ladid/>
</query>

In case when ladid is empty I want it to return "empty" string, if it's not empty - return ladid's value

VextoR
  • 5,087
  • 22
  • 74
  • 109

2 Answers2

1

In case you want to have the string empty instead of an empty sting as a result for empty elements the following XPath should do it:

concat(
    substring(string(/query/ladid), 1,
        number(string(/query/ladid) != '') * string-length(/query/ladid)),
    substring('empty', 1,
        number(string(/query/ladid) = '') * 5)
)

It is based on https://stackoverflow.com/a/971665/948404.

Community
  • 1
  • 1
hielsnoppe
  • 2,819
  • 3
  • 31
  • 56
0

Use the path string(/query/ladid).

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110