0

I want to check for a certain text in HTML, such as 'No Value', and if that exists then assign a 0 to it. Does anybody have any idea how to do that? (Google a lot but didn't find anything relevant)

<table>
<tr>
<td>
<h3>Money in account</h3>
</td>
<td>
<p>No Value</p>
</td>
</tr>
</table>
DT7
  • 1,615
  • 14
  • 26
  • Possible duplicate of [How to implement if-else statement in XSLT?](http://stackoverflow.com/questions/13622338/how-to-implement-if-else-statement-in-xslt) – Strelok Mar 04 '16 at 04:58
  • Possible duplicate of [Is there an "if -then - else " statement in XPath?](http://stackoverflow.com/questions/971067/is-there-an-if-then-else-statement-in-xpath) – Keith Hall Mar 04 '16 at 06:42

1 Answers1

2

In XPath 2.0:

if (p = 'No Value') then 0 else p

In XPath 1.0 there's no obvious solution but there are some convoluted workarounds: it depends a bit on the context in which you are working (e.g. can you declare variables).

It's time to move to XPath 2.0.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164