javascript/selenium-core/scripts/htmlutils.js
function eval_xpath(xpath, inDocument, opts)
{
    if (! opts) {
        var opts = {};
    }

    var contextNode = opts.contextNode
        ? opts.contextNode : inDocument;
    var namespaceResolver = opts.namespaceResolver
        ? opts.namespaceResolver : null;
    var xpathLibrary = opts.xpathLibrary
        ? opts.xpathLibrary : null;
    var allowNativeXpath = (opts.allowNativeXpath != undefined)
        ? opts.allowNativeXpath : true;
    var ignoreAttributesWithoutValue = (opts.ignoreAttributesWithoutValue != undefined)
        ? opts.ignoreAttributesWithoutValue : true;
    var returnOnFirstMatch = (opts.returnOnFirstMatch != undefined)
        ? opts.returnOnFirstMatch : false;

    if (! eval_xpath.xpathEvaluator) {
        eval_xpath.xpathEvaluator = new XPathEvaluator();
    }

    var xpathEvaluator = eval_xpath.xpathEvaluator;

    xpathEvaluator.setCurrentEngine(xpathLibrary);
    xpathEvaluator.setAllowNativeXPath(allowNativeXpath);
    xpathEvaluator.setIgnoreAttributesWithoutValue(ignoreAttributesWithoutValue);

    if (returnOnFirstMatch) {
        var singleNode = xpathEvaluator.selectSingleNode(inDocument, xpath,
            contextNode, namespaceResolver);

        var results = (singleNode ? [ singleNode ] : []);
    }
    else {
        var results = xpathEvaluator.selectNodes(inDocument, xpath, contextNode,
            namespaceResolver);
    }

    return results;
}
function eval_xpath(xpath, inDocument, opts)
{
    if (! opts) {
        var opts = {};
    }

    var contextNode = opts.contextNode
        ? opts.contextNode : inDocument;
    var namespaceResolver = opts.namespaceResolver
        ? opts.namespaceResolver : null;
    var xpathLibrary = opts.xpathLibrary
        ? opts.xpathLibrary : null;
    var allowNativeXpath = (opts.allowNativeXpath != undefined)
        ? opts.allowNativeXpath : true;
    var ignoreAttributesWithoutValue = (opts.ignoreAttributesWithoutValue != undefined)
        ? opts.ignoreAttributesWithoutValue : true;
    var returnOnFirstMatch = (opts.returnOnFirstMatch != undefined)
        ? opts.returnOnFirstMatch : false;

    if (! eval_xpath.xpathEvaluator) {
        eval_xpath.xpathEvaluator = new XPathEvaluator();
    }

    var xpathEvaluator = eval_xpath.xpathEvaluator;

    xpathEvaluator.setCurrentEngine(xpathLibrary);
    xpathEvaluator.setAllowNativeXPath(allowNativeXpath);
    xpathEvaluator.setIgnoreAttributesWithoutValue(ignoreAttributesWithoutValue);

    if (returnOnFirstMatch) {
        var singleNode = xpathEvaluator.selectSingleNode(inDocument, xpath,
            contextNode, namespaceResolver);

        var results = (singleNode ? [ singleNode ] : []);
    }
    else {
        var results = xpathEvaluator.selectNodes(inDocument, xpath, contextNode,
            namespaceResolver);
    }

    return results;
}
function eval_xpath ( xpath , inDocument , opts ) { if ( ! opts ) { var opts = { } ; } var contextNode = opts . contextNode ? opts . contextNode : inDocument ; var namespaceResolver = opts . namespaceResolver ? opts . namespaceResolver : null ; var xpathLibrary = opts . xpathLibrary ? opts . xpathLibrary : null ; var allowNativeXpath = ( opts . allowNativeXpath != undefined ) ? opts . allowNativeXpath : true ; var ignoreAttributesWithoutValue = ( opts . ignoreAttributesWithoutValue != undefined ) ? opts . ignoreAttributesWithoutValue : true ; var returnOnFirstMatch = ( opts . returnOnFirstMatch != undefined ) ? opts . returnOnFirstMatch : false ; if ( ! eval_xpath . xpathEvaluator ) { eval_xpath . xpathEvaluator = new XPathEvaluator ( ) ; } var xpathEvaluator = eval_xpath . xpathEvaluator ; xpathEvaluator . setCurrentEngine ( xpathLibrary ) ; xpathEvaluator . setAllowNativeXPath ( allowNativeXpath ) ; xpathEvaluator . setIgnoreAttributesWithoutValue ( ignoreAttributesWithoutValue ) ; if ( returnOnFirstMatch ) { var singleNode = xpathEvaluator . selectSingleNode ( inDocument , xpath , contextNode , namespaceResolver ) ; var results = ( singleNode ? [ singleNode ] : [ ] ) ; } else { var results = xpathEvaluator . selectNodes ( inDocument , xpath , contextNode , namespaceResolver ) ; } return results ; }
Evaluates an xpath on a document, and returns a list containing nodes in the
resulting nodeset. The browserbot xpath methods are now backed by this
function. A context node may optionally be provided, and the xpath will be
evaluated from that context.

@param xpath       the xpath to evaluate
@param inDocument  the document in which to evaluate the xpath.
@param opts        (optional) An object containing various flags that can
modify how the xpath is evaluated. Here's a listing of
the meaningful keys:

contextNode:
the context node from which to evaluate the xpath. If
unspecified, the context will be the root document
element.

namespaceResolver:
the namespace resolver function. Defaults to null.

xpathLibrary:
the javascript library to use for XPath. "ajaxslt" is
the default. "javascript-xpath" is newer and faster,
but needs more testing.

allowNativeXpath:
whether to allow native evaluate(). Defaults to true.

ignoreAttributesWithoutValue:
whether it's ok to ignore attributes without value
when evaluating the xpath. This can greatly improve
performance in IE; however, if your xpaths depend on
such attributes, you can't ignore them! Defaults to
true.

returnOnFirstMatch:
whether to optimize the XPath evaluation to only
return the first match. The match, if any, will still
be returned in a list. Defaults to false.
Evaluates an xpath on a document and returns a list containing nodes in the resulting nodeset . The browserbot xpath methods are now backed by this function . A context node may optionally be provided and the xpath will be evaluated from that context .