In the previous section we saw how an XPath function can be built to locate a node. The sps:Stock function which is defined as shown in the screenshot below returns the /Trades/Stock element that has a name attribute with a value that matches the content of the /Trades/Selection/Stock element.
We could modularize the location steps of the XPath expression $XML/Trades/Stock[@name=$XML/Trades/Selection/Stock] into separate XPath functions. For example as follows:
•The function sps:Stocks(), with the definition: $XML/Trades/Stock
•The function sps:SelectedStock(), with the definition: $XML/Trades/Selection/Stock
The whole XPath expression can then be written in another XPath expression as:
When XPath functions are created in this way to locate a node or nodeset, these functions can be re-used in other XPath expressions across the SPS design, thus considerably simplifying the writing of complex XPath expressions.