This answer is for XPath 1.0 where there is no equivalent of the XPath 2.0 standard ends-with() function.
The following XPath 1.0 expression selects all elements in the xml document, whose names end with the string “fu”:
//*[substring(name(),string-length(name())-1) = 'fu']
Note that -1
is the offset from the end of name()
(the length of "fu"
minus one), so that the string comparison performed within substring()
starts at the right position from the end of the string.
Similarly, if it was needed to determine whether "asdf"
was a suffix of the name, then string-length(name())-3
must be specified.