xPath

Description

XSH supports arbitrary XPath expression as defined in W3C recommendation at http://www.w3.org/TR/xpath. (Nice interactive XPath tutorials and references can be found at http://www.zvon.org.) In XSH, XPath expressoin may be optionally preceded with a document identifier followed by colon (id:xpath). If no document identifier is given, the current document is used.

As an extension, the following XPath extension functions are defined in the XSH namespace:

xsh:doc(id-string) - returns a nodelist consisting of the document node associated in XSH with an identifier given in id-string.

xsh:matches(match-string,regexp-string) - returns true if match-string matches the regular expression given in regexp-string. Otherwise returns false.

xsh:grep(node-set, regexp-string) - returns a node set consisting of nodes of the given node-set whose content (as returned by the built-in XPath function string()) matches the regular expression given in regexp-string.

xsh:same(node-set1, node-set2) - returns true if the given node sets both contain the same node (in XPath, this can also be expressed as count(node-set1|node-set2)+count(node-set1)+count(node-set2)=1).

Example 36. Open a document and count all sections containing a subsection

xsh scratch:/> open v = mydocument1.xml;
xsh v:/> open k = mydocument2.xml;
xsh k:/> count //section[subsection];# searches k
xsh k:/> count v://section[subsection];# searches v