I am using PostgreSQL 9, that adopts XPath-1 for the SQL/XML standard cumpliance.
This query is ok, returns the expected data:
SELECT xpath('//img',xhtm) FROM t
but this other one, to count img elements, returns empty (!),
SELECT xpath('count(//img)',xhtm) FROM t
NOTE 1: a xhtm
field content sample,
<html><p>Hello! <img src="1.png"/></p><img src="2.jpg"/></html>
NOTE 2: of course array_length(xpath('//img',xhtm),1)
show the count result, but it is not a XPath counting.
NOTE 3: I don't know if it is a generic SQL/XML peculiarity, or a PosgreSQL Server 9.0.5 specific bug/problem.