You could use the fn:exists()
function to test whether or not there is a text()
node.
exists($output.dataAccessResponse[1]/:row/:name/text())
You could also use the fn:boolean()
function to test the effective boolean value of the node.
boolean($output.dataAccessResponse[1]/:row/:name/text())
If you wanted to test whether or not there was a significant value i.e. something other than whitespace, you can fn:normalize-space()
in a predicate, to ensure that only text()
nodes that have meaningful text are selected, and then test fn:exists()
.
exists($output.dataAccessResponse[1]/:row/:name/text()[normalize-space()])
XQuery doesn't have null
, so if you are asking what to return to indicate null
, then you would want to return an empty sequence ()
instead of null
.
So, you could execute something like this:
let $name := $output.dataAccessResponse[1]/:row/:name/text()
return
if (fn:exists($name))
then $name
else ()
But at that point, it's really the same as just attempting to select the text()
with that XPath and it will either return the text()
node or an empty sequence:
$output.dataAccessResponse[1]/:row/:name/text()