B2G/gecko/browser/components/sessionstore/src/XPathGenerator.jsm
/**
   * Generates an approximate XPath query to an (X)HTML node
   */
Generates an approximate XPath query to an (X)HTML node
Generates an approximate XPath query to an ( X ) HTML node
function sss_xph_generate(aNode) {
    if (!aNode.parentNode)
      return "";
    let nNamespaceURI = aNode.namespaceURI;
    let nLocalName = aNode.localName;
    let prefix = this.namespacePrefixes[nNamespaceURI] || null;
    let tag = (prefix ? prefix + ":" : "") + this.escapeName(nLocalName);
    if (aNode.id)
      return "//" + tag + "[@id=" + this.quoteArgument(aNode.id) + "]";
    let count = 0;
    let nName = aNode.name || null;
    for (let n = aNode; (n = n.previousSibling); )
      if (n.localName == nLocalName && n.namespaceURI == nNamespaceURI &&
          (!nName || n.name == nName))
        count++;
    return this.generate(aNode.parentNode) + "/" + tag +
           (nName ? "[@name=" + this.quoteArgument(nName) + "]" : "") +
           (count ? "[" + (count + 1) + "]" : "");
  }
function sss_xph_generate ( aNode ) { if ( ! aNode . parentNode ) return "" ; let nNamespaceURI = aNode . namespaceURI ; let nLocalName = aNode . localName ; let prefix = this . namespacePrefixes [ nNamespaceURI ] || null ; let tag = ( prefix ? prefix + ":" : "" ) + this . escapeName ( nLocalName ) ; if ( aNode . id ) return "//" + tag + "[@id=" + this . quoteArgument ( aNode . id ) + "]" ; let count = 0 ; let nName = aNode . name || null ; for ( let n = aNode ; ( n = n . previousSibling ) ; ) if ( n . localName == nLocalName && n . namespaceURI == nNamespaceURI && ( ! nName || n . name == nName ) ) count ++ ; return this . generate ( aNode . parentNode ) + "/" + tag + ( nName ? "[@name=" + this . quoteArgument ( nName ) + "]" : "" ) + ( count ? "[" + ( count + 1 ) + "]" : "" ) ; }
Generates an approximate XPath query to an (X)HTML node
Generates an approximate XPath query to an ( X ) HTML node
// have we reached the document node already? // Access localName, namespaceURI just once per node since it's expensive. // stop once we've found a tag with an ID // count the number of previous sibling nodes of the same tag // (and possible also the same name) // recurse until hitting either the document node or an ID'd node