Can XPath match on parts of an element’s name?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)