Advanced XPath Features

Advanced XPath Features

For more complex scenarios, XPath provides regular expressions, variable assignments, and special functions to manipulate and evaluate XML data dynamically.

This section covers these advanced features.

Working with regular expressions in XPath

Using variables in XPat

Working with regular expressions in XPath

You can use regular expressions with Xpath, if you use the matches Xpath function. This expression checks the variable, MyVariable:

matches($MyVariable, "^(DIN|ISO) A[3-5]$")

The regular expression above tests, if the variable:

starts with either 'DIN' or 'ISO'

then a space and the letter 'A'

finish with 3, 4 or 5

 

You can use the expression in IF- and select elements to let the output depend on the result of a test.

 

Remember, that you can combine the XPath functions, and that there are many other functions not mentioned here. This appendix hopefully gives you an idea of how strong a tool this is. You can e.g. refer to this link for additional information: https://www.w3schools.com/js/js_regexp.asp


Using variables in XPath
XPath is a strong tool so you can even use variables in your XPath expressions. 
More detailed information about variables can be found here