To return the first occurrence instead of no result in case there are multiple nodes with maximum visits
, change your XPath to use <
instead of <=
:
/Pages/Page/@visits[
not(. < ../preceding-sibling::Page/@visits)
and
not(. < ../following-sibling::Page/@visits)
]
UPDATE :
In addition to above XPath, to also filter out empty visits
, you can try this way :
/Pages/Page/@visits[
not(. < ../preceding-sibling::Page/@visits)
and
not(. < ../following-sibling::Page/@visits)
and
normalize-space(.)
]