From 03fe3865473668a756b8de8c998fbe10a943bd2c Mon Sep 17 00:00:00 2001 From: Martijn van de Rijdt Date: Fri, 26 May 2017 11:46:47 -0600 Subject: [PATCH] added: count-non-empty() support, closes #66 --- CHANGELOG.md | 5 ++++ dist/enketo-xpathjs.js | 36 +++++++++++++--------------- dist/enketo-xpathjs.min.js | 4 +--- src/engine.js | 36 +++++++++++++--------------- test/doc.xml | 15 ++++++++++++ test/spec/functions-openrosa.spec.js | 30 +++++++++++++++++++++++ 6 files changed, 85 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a9830f..e1a523b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +[Unreleased] +-------------------- +##### Added +- Count-non-empty() support. + [1.5.0] - 2017-04-25 -------------------- ##### Added diff --git a/dist/enketo-xpathjs.js b/dist/enketo-xpathjs.js index 73ba2e9..077eee5 100644 --- a/dist/enketo-xpathjs.js +++ b/dist/enketo-xpathjs.js @@ -4002,33 +4002,32 @@ var XPathJS = (function(){ //}, /********************************************************************/ - /**** JAVAROSA-specific XPath functions (or XPath 2.0 functions) ****/ + /**** OpenRosa-specific XPath functions (or XPath 2.0 functions) ****/ /********************************************************************/ - sum_jr: { + 'count-non-empty': { /** - * The JavaRosa version of the sum function is the same as the XPath 1.0 function - * EXCEPT that it evaluates an empty node ('') to 0 instead of NaN. - * @obsolete - * @see - * @param {NodeSetType} + * The count-non-empty function returns the number of non-empty nodes in argument node-set. + * A node is considered non-empty if it is convertible into a string with a greater-than zero length. + * + * @see https://www.w3.org/TR/2003/REC-xforms-20031014/slice7.html#fn-count-non-empty + * @param {NodeSetType} nodeset * @return {NumberType} */ fn: function(nodeset) { - var i, value - sum = 0; - ; - + var i; + var count=0; + nodeset = nodeset.toNodeSet(); - - for(i = 0; i < nodeset.length; i++) - { - value = ( nodeStringValue(nodeset[i]) == '' ) ? '0' : nodeStringValue(nodeset[i]); - sum += (new StringType(value)).toNumber(); + + for ( i=0 ; i < nodeset.length ; i++){ + if ((new StringType(nodeStringValue(nodeset[i]))).toString().length > 0) { + count++; + } } - - return new NumberType(sum); + + return new NumberType(count); }, args: [ @@ -4038,7 +4037,6 @@ var XPathJS = (function(){ ret: 'number' }, - position: { /** * Hacked OpenRosa function to return the position of a nodeset argument diff --git a/dist/enketo-xpathjs.min.js b/dist/enketo-xpathjs.min.js index b648cc9..feaf63a 100644 --- a/dist/enketo-xpathjs.min.js +++ b/dist/enketo-xpathjs.min.js @@ -1,3 +1 @@ -var XPathJS=function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=[],s="http://www.w3.org/XML/1998/namespace",t=function(a){return a.ownerDocument},u=function(a){var b=[],c=function(a,b){var c,d,e=[];for(d=0;d1&&c[0].compareDocumentPosition&&c.sort(function(a,b){var c=a.compareDocumentPosition(b);return 2==(2&c)?1:4==(4&c)?-1:0}),c},G=function(a){var b,c=F(a),d=[];for(b=0;b=0;d--)f=a.ownerDocument.namespaces.item(d),I.call(this,g,f.name,f.urn,a);for(c=F(a),d=c.length-1;d>=0;d--)!1!==(e=J(c[d]))&&(1!==e.length?I.call(this,g,e[1],c[d].nodeValue,a):I.call(this,g,"",c[d].nodeValue,a));if(H.call(this,a.parentNode,g),void 0===b&&(I.call(this,g,"xml",s,a),g[0]&&""===g[0].prefix&&""===g[0].namespaceURI&&g.shift()),void 0===b)for(d=0;d=0&&d.sourceIndex>=0?(c.sourceIndexd.sourceIndex&&2):1)+0}if(a===c&&b===d)return e;if(a===c)return h(a,c,b,d,e,16,8,4,2);if(b===d)return h(b,d,a,c,e,8,16,2,4);if(16==(16&e))return 4;if(8==(8&e))return 2;if(0===e){for(f=0;f0},p.prototype.toString=function(){return this.value.length<1?"":(this.sortDocumentOrder(),N(this.value[0]))},p.prototype.toNumber=function(){return new n(this.toString()).toNumber()},p.prototype.toNodeSet=function(){return this.value},p.prototype.toDate=function(){return new n(this.toString()).toDate()},p.prototype.sortDocumentOrder=function(){switch(this.docOrder){case"document-order":break;case"reverse-document-order":this.value.reverse();break;default:this.value.sort(function(a,b){var c=S(a,b);if(4==(4&c))return-1;if(2==(2&c))return 1;throw new Error("NodeSetType.sortDocumentOrder - unexpected compare result: "+c)})}this.docOrder="document-order"},p.prototype.sortReverseDocumentOrder=function(){switch(this.docOrder){case"document-order":this.value.reverse();break;case"reverse-document-order":break;default:this.sortDocumentOrder(),this.value.reverse()}this.docOrder="reverse-document-order"},p.prototype.append=function(a){var b,c=0,d=0;if(!a instanceof p)throw new Error("NodeSetType can be passed into NodeSetType.append method");for(this.sortDocumentOrder(),a.sortDocumentOrder();c0},n.prototype.toString=function(){return this.value},n.prototype.toNumber=function(){var a;return this.isDateString(this.value)?new DateType(this.value).toNumber():null!==(a=this.value.match(/^[ \t\r\n]*(-?[0-9]+(?:[.][0-9]*)?)[ \t\r\n]*$/))?parseFloat(a[1]):(a=this.value.match(/^[ \t\r\n]*(-?[.][0-9]+)[ \t\r\n]*$/),null!==a?parseFloat(a[1]):Number.NaN)},n.prototype.toDate=function(){return new Date(this.value)},n.prototype.isDateString=function(){return!!isNaN(this.value)&&(!isNaN(Date.parse(this.value))&&!!/('|")?[0-9]{4}(-|\/)[0-9]{2}(-|\/)[0-9]{2}('|")?/.test(this.value))},o=function(a){l.call(this,a,"number",["boolean","string","number","date"])},o.prototype=new l,o.constructor=o,o.prototype.toBoolean=function(){return 0!==this.value&&!isNaN(this.value)},o.prototype.toString=function(){return this.value.toString()},o.prototype.toNumber=function(){return this.value},o.prototype.toDate=function(){return new Date(864e5*this.value)},DateType=function(a){l.call(this,a,"date",["date","string","number","boolean"])},DateType.prototype=new l,DateType.constructor=DateType,DateType.prototype.toDate=function(){return new Date(this.value)},DateType.prototype.toString=function(){return new Date(this.value).toUTCString()},DateType.prototype.toNumber=function(){return new Date(this.value).getTime()/864e5},DateType.prototype.toBoolean=function(){return!isNaN(new Date(this.value).getTime())},a=function(b,c){var d;switch(this.code=b,this.code){case a.INVALID_EXPRESSION_ERR:this.name="INVALID_EXPRESSION_ERR";break;case a.TYPE_ERR:this.name="TYPE_ERR";break;default:throw d=new Error("Unsupported XPathException code: "+this.code),d.name="XPathExceptionInternalError",d}this.message=c||""},a.prototype.toString=function(){return'XPathException: "'+this.message+'", code: "'+this.code+'", name: "'+this.name+'"'},a.INVALID_EXPRESSION_ERR=51,a.TYPE_ERR=52,b=function(a){var b,c,d;for(b in a){d=!1;for(c in this.opts)if(b===c){this.opts[b]=a[b],d=!0;break}if(!d)throw new Error("Unsupported option: "+b)}this.opts["unique-ids"][s]="id",this.opts["unique-ids"]["http://www.w3.org/1999/xhtml"]="id"},b.prototype={opts:{"unique-ids":{},"case-sensitive":!1},createExpression:function(b,d){var e,f,g,h,i={};try{e=XPathJS._parser.parse(b)}catch(b){throw f="The expression is not a legal expression.",f+=b instanceof XPathJS._parser.SyntaxError?" (line: "+b.line+", character: "+b.column+")":" ("+b.message+")",new a(a.INVALID_EXPRESSION_ERR,f)}if(e.nsPrefixes.length>0){if("object"!=typeof d||void 0===d.lookupNamespaceURI)throw new a(a.INVALID_EXPRESSION_ERR,"No namespace resolver provided or lookupNamespaceURI function not supported.");for(g=0;g=0;d--)switch(b.args[0]){case"text":3!=c.value[d].nodeType&&4!=c.value[d].nodeType&&c.value.splice(d,1);break;case"comment":8!=c.value[d].nodeType&&c.value.splice(d,1);break;case"processing-instruction":(7!=c.value[d].nodeType||b.args[1].length>0&&h(this,b.args[1][0])!=c.value[d].nodeName)&&c.value.splice(d,1)}break;case"name":switch(g=h(this,b),a){case"attribute":i=2;break;case"namespace":i=13;break;default:i=1}for(d=c.value.length-1;d>=0;d--)c.value[d].nodeType==i?null===g.ns&&null===g.name||(j=M.call(this,c.value[d]),j!==!1&&j.ns===g.ns?null!==g.name&&j.name.toLowerCase()!=g.name.toLowerCase()&&c.value.splice(d,1):c.value.splice(d,1)):c.value.splice(d,1);break;default:throw new Error("NodeTest type not supported in step: "+b.type)}return c},predicate:function(a,b,c){var d,e,f,g,i,j;if(!(d=h(this,b))instanceof p)throw new Error('Expected "node-set", got: '+d.type);switch(a){case"ancestor":case"ancestor-or-self":case"preceding":case"preceding-sibling":d.sortReverseDocumentOrder();break;default:d.sortDocumentOrder()}for(g=0;g=":function(a,b){return Q.call(this,h(this,a),h(this,b),">=",function(a,b){return a>=b})},">":function(a,b){return Q.call(this,h(this,a),h(this,b),">",function(a,b){return a>b})},"+":function(a,b){return new o(h(this,a).toNumber()+h(this,b).toNumber())},"-":function(a,b){return new o(h(this,a).toNumber()-h(this,b).toNumber())},div:function(a,b){return new o(h(this,a).toNumber()/h(this,b).toNumber())},mod:function(a,b){return new o(h(this,a).toNumber()%h(this,b).toNumber())},"*":function(a,b){return new o(h(this,a).toNumber()*h(this,b).toNumber())},string:function(a){return new n(a)},number:function(a){return new o(a)},$:function(a){throw new Error("TODO: Not implemented.16")},name:function(a,b){var c=null;if(null!==a&&!(c=this.nsMap[a]))throw new Error('Namespace prefix "'+a+'" is not mapped to a namespace.');return{ns:c,name:b}}},j={"":{last:{fn:function(){return new o(this.size)},ret:"number"},count:{fn:function(a){return new o(a.toNodeSet().length)},args:[{t:"node-set"}],ret:"number"},id:{fn:function(a){var b,c,d,e=this,f=[],g=[],h=function(a){var b,c=a.split(/[\u0020\u0009\u000D\u000A]+/);for(b=c.length-1;b>=0;b--)0==c[b].length&&c.splice(b,1);return c};if(a instanceof p)for(b=0;b=0;b--)for(c=b-1;c>=0;c--)if(f[b]==f[c]&&b!=c){f.splice(b,1);break}for(b=0;b0&&(a.sortDocumentOrder(),(b=M.call(this,a.value[0]))!==!1&&(c=b.name)),new n(c)},args:[{t:"node-set",r:!1}],ret:"string"},"namespace-uri":{fn:function(a){var b,c="";return 0==arguments.length&&(a=new p([this.node])),a.toNodeSet().length>0&&(a.sortDocumentOrder(),(b=M.call(this,a.value[0]))!==!1&&null!==b.ns&&(c=b.ns)),new n(c)},args:[{t:"node-set",r:!1}],ret:"string"},name:{fn:function(a){var b,c="";return 0==arguments.length&&(a=new p([this.node])),a.toNodeSet().length>0&&(a.sortDocumentOrder(),(b=M.call(this,a.value[0]))!==!1&&(c=b.prefix&&b.prefix.length>0?b.prefix+":"+b.name:b.name)),new n(c)},args:[{t:"node-set",r:!1}],ret:"string"},string:{fn:function(a){return 0==arguments.length&&(a=new p([this.node],"document-order")),new n(a.toString())},args:[{t:"object",r:!1}],ret:"string"},"starts-with":{fn:function(a,b){return new m(a.toString().substr(0,(b=b.toString()).length)==b)},args:[{t:"string"},{t:"string"}],ret:"string"},contains:{fn:function(a,b){return new m(a.toString().indexOf(b=b.toString())!=-1)},args:[{t:"string"},{t:"string"}],ret:"string"},"substring-before":{fn:function(a,b){return a=a.toString(),b=a.indexOf(b.toString()),new n(b==-1?"":a.substr(0,b))},args:[{t:"string"},{t:"string"}],ret:"string"},"substring-after":{fn:function(a,b){var c;return a=a.toString(),b=b.toString(),c=a.indexOf(b),new n(c==-1?"":a.substr(c+b.length))},args:[{t:"string"},{t:"string"}],ret:"string"},substring:{fn:function(a,b,c){return a=a.toString(),b=Math.round(b.toNumber())-1,new n(isNaN(b)?"":2==arguments.length?a.substring(b<0?0:b):a.substring(b<0?0:b,b+Math.round(c.toNumber())))},args:[{t:"string"},{t:"number"},{t:"number",r:!1}],ret:"string"},"string-length":{fn:function(a){return a=0==arguments.length?N(this.node):a.toString(),new o(a.length)},args:[{t:"string",r:!1}],ret:"number"},"normalize-space":{fn:function(a){return a=0==arguments.length?N(this.node):a.toString(),new n(a.replace(/^[\u0020\u0009\u000D\u000A]+/,"").replace(/[\u0020\u0009\u000D\u000A]+$/,"").replace(/[\u0020\u0009\u000D\u000A]+/g," "))},args:[{t:"string",r:!1}],ret:"string"},translate:{fn:function(a,b,c){var d,e,f,g="";for(a=a.toString(),b=b.toString(),c=c.toString(),d=0;d=0&&b0?(b=N(a[0]).trim().split(" "),new o(1==b.length&&""===b[0]?0:b.length)):new o(0)},args:[{t:"node-set"}],ret:"number"},checklist:{fn:function(a,b,c){var d,e,f=0;for(a=a.toNumber(),b=b.toNumber(),d=2;d=a)&&(b<0||f<=b))},args:[{t:"number"},{t:"number"},{t:"object"},{t:"object",r:!1,rep:!0}],ret:"boolean"},"weighted-checklist":{fn:function(a,b,c,d){var e,f=[],g=[],h=0;for(a=a.toNumber(),b=b.toNumber(),e=2;e=a)&&(b<0||h<=b))},args:[{t:"number"},{t:"number"},{t:"object"},{t:"object"},{t:"object",r:!1,rep:!0}],ret:"boolean"},"boolean-from-string":{fn:function(a){return new m("true"===a.toString().toLowerCase()||"1"===String(a))},args:[{t:"string"}],ret:"boolean"},if:{fn:function(a,b,c){return a.toBoolean()?b:c},args:[{t:"object"},{t:"object"},{t:"object"}],ret:"object"},date:{fn:function(a){return new DateType(a.toDate())},args:[{t:"object"}],ret:"string"},"date-time":{fn:function(a){return new DateType(a.toDate())},args:[{t:"object"}],ret:"string"},"decimal-date-time":{fn:function(a){return new DateType(a.toDate())},args:[{t:"object"}],ret:"string"},today:{fn:function(){var a=new Date;return new DateType(new Date(a.getFullYear(),a.getMonth(),a.getDate()))},ret:"string"},now:{fn:function(){return new DateType(new Date)},ret:"string"},regex:{fn:function(a,b){var c,d;return c=a.toString(),d=new RegExp(b),new m(d.test(c))},args:[{t:"object"},{t:"string"}],ret:"boolean"},uuid:{fn:function(){return new n("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0;return("x"==a?b:3&b|8).toString(16)}))},ret:"string"},int:{fn:function(a){return new o(a.toNumber()>=0?Math.floor(a.toNumber()):-Math.floor(Math.abs(a.toNumber())))},args:[{t:"string"}],ret:"number"},substr:{fn:function(a,b,c){return a=a.toString(),length=a.length,b=Math.round(b.toNumber()),c=c?Math.round(c.toNumber()):length,new n(isNaN(b)?"":a.substring(b<0?length+b:b,c<0?length+c:c))},args:[{t:"string"},{t:"number"},{t:"number",r:!1}],ret:"string"},random:{fn:function(){return new o(Math.random().toFixed(15))},ret:"number"},min:{fn:function(a,b){var c,d,e,f,g;for(c=0;c0?a:b},args:[{t:"object"},{t:"object"}],ret:"string"},"format-date":{fn:function(a,b){var c,a=new DateType(a),d=a.toDate(),e=b.toString(),f=function(a,b){var d=a.toString(),e=b-d.length;for(c=0;c1?a.value.forEach(function(a){c.push(N(a))}):a instanceof p?c=N(a.value[0]).split(";"):a instanceof n&&(c=a.value.split(";")),d=c.map(function(a){return a.trim().split(" ")}),d.every(function(a){return""!==a[0]&&a[0]>=-90&&a[0]<=90&&""!==a[1]&&a[1]>=-180&&a[1]<=180&&(void 0===a[2]||!isNaN(a[2]))&&(void 0===a[3]||!isNaN(a[3])&&a[3]>=0)})){var e,f,g=d.length,h=Math.PI/180;if(b=0,g>2){for(var i=0;ikd&&(kd=hd,ld=[]),ld.push(a))}function f(b,c,d,e){return null!==c&&function(a){var b=1;for(a.sort(function(a,b){return a.descriptionb.description?1:0});b1?f.slice(0,-1).join(", ")+" or "+f[a.length-1]:f[0],d=b?'"'+function(a){function b(a){return a.charCodeAt(0).toString(16).toUpperCase()}return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(a){return"\\x0"+b(a)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(a){return"\\x"+b(a)}).replace(/[\u0100-\u0FFF]/g,function(a){return"\\u0"+b(a)}).replace(/[\u1000-\uFFFF]/g,function(a){return"\\u"+b(a)})}(b)+'"':"end of input","Expected "+c+" but "+d+" found."}(c,d),c,d,e)}function g(){var a,b,c,d;return a=hd,b=O(),b!==Y?(c=s(),c!==Y?(d=O(),d!==Y?(id=a,b=_(c),a=b):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a}function h(){var a;return a=j(),a===Y&&(a=i()),a}function i(){var a,c,d,f,g;return a=p(),a===Y&&(a=hd,47===b.charCodeAt(hd)?(c=aa,hd++):(c=Y,0===md&&e(ba)),c!==Y?(d=hd,f=O(),f!==Y?(g=j(),g!==Y?(f=[f,g],d=f):(hd=d,d=Y)):(hd=d,d=Y),d===Y&&(d=null),d!==Y?(id=a,c=ca(d),a=c):(hd=a,a=Y)):(hd=a,a=Y)),a}function j(){var a,c,d,f,g,h,i,j;if(a=hd,(c=k())!==Y){for(d=[],f=hd,g=O(),g!==Y?(b.substr(hd,2)===da?(h=da,hd+=2):(h=Y,0===md&&e(ea)),h===Y&&(47===b.charCodeAt(hd)?(h=aa,hd++):(h=Y,0===md&&e(ba))),h!==Y?(i=O(),i!==Y?(j=k(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(b.substr(hd,2)===da?(h=da,hd+=2):(h=Y,0===md&&e(ea)),h===Y&&(47===b.charCodeAt(hd)?(h=aa,hd++):(h=Y,0===md&&e(ba))),h!==Y?(i=O(),i!==Y?(j=k(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=fa(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function k(){var a,b,c,d,e,f,g;if(a=hd,(b=l())!==Y)if(O()!==Y)if((c=n())!==Y){for(d=[],e=hd,f=O(),f!==Y?(g=o(),g!==Y?(f=[f,g],e=f):(hd=e,e=Y)):(hd=e,e=Y);e!==Y;)d.push(e),e=hd,f=O(),f!==Y?(g=o(),g!==Y?(f=[f,g],e=f):(hd=e,e=Y)):(hd=e,e=Y);d!==Y?(id=a,b=ga(b,c,d),a=b):(hd=a,a=Y)}else hd=a,a=Y;else hd=a,a=Y;else hd=a,a=Y;return a===Y&&(a=q()),a}function l(){var a,c,d,f;return a=hd,c=m(),c!==Y?(d=O(),d!==Y?(b.substr(hd,2)===ha?(f=ha,hd+=2):(f=Y,0===md&&e(ia)),f!==Y?(id=a,c=ja(c),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,c=r(),c!==Y&&(id=a,c=ka(c)),a=c),a}function m(){var a;return b.substr(hd,16)===la?(a=la,hd+=16):(a=Y,0===md&&e(ma)),a===Y&&(b.substr(hd,8)===na?(a=na,hd+=8):(a=Y,0===md&&e(oa)),a===Y&&(b.substr(hd,9)===pa?(a=pa,hd+=9):(a=Y,0===md&&e(qa)),a===Y&&(b.substr(hd,5)===ra?(a=ra,hd+=5):(a=Y,0===md&&e(sa)),a===Y&&(b.substr(hd,18)===ta?(a=ta,hd+=18):(a=Y,0===md&&e(ua)),a===Y&&(b.substr(hd,10)===va?(a=va,hd+=10):(a=Y,0===md&&e(wa)),a===Y&&(b.substr(hd,17)===xa?(a=xa,hd+=17):(a=Y,0===md&&e(ya)),a===Y&&(b.substr(hd,9)===za?(a=za,hd+=9):(a=Y,0===md&&e(Aa)),a===Y&&(b.substr(hd,9)===Ba?(a=Ba,hd+=9):(a=Y,0===md&&e(Ca)),a===Y&&(b.substr(hd,6)===Da?(a=Da,hd+=6):(a=Y,0===md&&e(Ea)),a===Y&&(b.substr(hd,17)===Fa?(a=Fa,hd+=17):(a=Y,0===md&&e(Ga)),a===Y&&(b.substr(hd,9)===Ha?(a=Ha,hd+=9):(a=Y,0===md&&e(Ia)),a===Y&&(b.substr(hd,4)===Ja?(a=Ja,hd+=4):(a=Y,0===md&&e(Ka)))))))))))))),a}function n(){var a,c,d,f,g,h,i,j;return a=hd,c=M(),c!==Y?(d=O(),d!==Y?(40===b.charCodeAt(hd)?(f=La,hd++):(f=Y,0===md&&e(Ma)),f!==Y?(g=O(),g!==Y?(41===b.charCodeAt(hd)?(h=Na,hd++):(h=Y,0===md&&e(Oa)),h!==Y?(id=a,c=Pa(c),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,b.substr(hd,22)===Qa?(c=Qa,hd+=22):(c=Y,0===md&&e(Ra)),c!==Y?(d=O(),d!==Y?(40===b.charCodeAt(hd)?(f=La,hd++):(f=Y,0===md&&e(Ma)),f!==Y?(g=O(),g!==Y?(h=F(),h!==Y?(i=O(),i!==Y?(41===b.charCodeAt(hd)?(j=Na,hd++):(j=Y,0===md&&e(Oa)),j!==Y?(id=a,c=Sa(c,h),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,c=L(),c!==Y&&(id=a,c=Ta(c)),a=c)),a}function o(){var a,c,d,f,g,h;return a=hd,91===b.charCodeAt(hd)?(c=Ua,hd++):(c=Y,0===md&&e(Va)),c!==Y?(d=O(),d!==Y?(f=s(),f!==Y?(g=O(),g!==Y?(93===b.charCodeAt(hd)?(h=Wa,hd++):(h=Y,0===md&&e(Xa)),h!==Y?(id=a,c=Ya(f),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a}function p(){var a,c,d,f;return a=hd,b.substr(hd,2)===da?(c=da,hd+=2):(c=Y,0===md&&e(ea)),c!==Y?(d=O(),d!==Y?(f=j(),f!==Y?(id=a,c=Za(f),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a}function q(){var a,c;return a=hd,b.substr(hd,2)===$a?(c=$a,hd+=2):(c=Y,0===md&&e(_a)),c===Y&&(46===b.charCodeAt(hd)?(c=ab,hd++):(c=Y,0===md&&e(bb))),c!==Y&&(id=a,c=cb(c)),a=c}function r(){var a,c;return a=hd,64===b.charCodeAt(hd)?(c=db,hd++):(c=Y,0===md&&e(eb)),c===Y&&(c=null),c!==Y&&(id=a,c=fb(c)),a=c}function s(){var a,b;return a=hd,b=y(),b!==Y&&(id=a,b=Ya(b)),a=b}function t(){var a,c,d,f,g,h;return a=hd,c=K(),c!==Y&&(id=a,c=gb(c)),a=c,a===Y&&(a=hd,40===b.charCodeAt(hd)?(c=La,hd++):(c=Y,0===md&&e(Ma)),c!==Y?(d=O(),d!==Y?(f=s(),f!==Y?(g=O(),g!==Y?(41===b.charCodeAt(hd)?(h=Na,hd++):(h=Y,0===md&&e(Oa)),h!==Y?(id=a,c=Ya(f),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,c=F(),c!==Y&&(id=a,c=hb(c)),(a=c)===Y&&(a=hd,c=G(),c!==Y&&(id=a,c=ib(c)),(a=c)===Y&&(a=u())))),a}function u(){var a,c,d,f,g,h,i,j,k,l,m,n;if(a=hd,(c=J())!==Y)if(O()!==Y)if(40===b.charCodeAt(hd)?(d=La,hd++):(d=Y,0===md&&e(Ma)),d!==Y){if(f=hd,(g=O())!==Y)if((h=s())!==Y){for(i=[],j=hd,k=O(),k!==Y?(44===b.charCodeAt(hd)?(l=jb,hd++):(l=Y,0===md&&e(kb)),l!==Y?(m=O(),m!==Y?(n=s(),n!==Y?(k=[k,l,m,n],j=k):(hd=j,j=Y)):(hd=j,j=Y)):(hd=j,j=Y)):(hd=j,j=Y);j!==Y;)i.push(j),j=hd,k=O(),k!==Y?(44===b.charCodeAt(hd)?(l=jb,hd++):(l=Y,0===md&&e(kb)),l!==Y?(m=O(),m!==Y?(n=s(),n!==Y?(k=[k,l,m,n],j=k):(hd=j,j=Y)):(hd=j,j=Y)):(hd=j,j=Y)):(hd=j,j=Y);i!==Y?(g=[g,h,i],f=g):(hd=f,f=Y)}else hd=f,f=Y;else hd=f,f=Y;f===Y&&(f=null),f!==Y?(g=O(),g!==Y?(41===b.charCodeAt(hd)?(h=Na,hd++):(h=Y,0===md&&e(Oa)),h!==Y?(id=a,c=lb(c,f),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)}else hd=a,a=Y;else hd=a,a=Y;else hd=a,a=Y;return a}function v(){var a,c,d,f,g,h,i,j;if(a=hd,(c=w())!==Y){for(d=[],f=hd,g=O(),g!==Y?(124===b.charCodeAt(hd)?(h=mb,hd++):(h=Y,0===md&&e(nb)),h!==Y?(i=O(),i!==Y?(j=w(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(124===b.charCodeAt(hd)?(h=mb,hd++):(h=Y,0===md&&e(nb)),h!==Y?(i=O(),i!==Y?(j=w(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function w(){var a,c,d,f,g,i,k;return a=hd,c=x(),c!==Y?(d=hd,f=O(),f!==Y?(b.substr(hd,2)===da?(g=da,hd+=2):(g=Y,0===md&&e(ea)),g===Y&&(47===b.charCodeAt(hd)?(g=aa,hd++):(g=Y,0===md&&e(ba))),g!==Y?(i=O(),i!==Y?(k=j(),k!==Y?(f=[f,g,i,k],d=f):(hd=d,d=Y)):(hd=d,d=Y)):(hd=d,d=Y)):(hd=d,d=Y),d===Y&&(d=null),d!==Y?(id=a,c=pb(c,d),a=c):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,c=h(),c!==Y&&(id=a,c=qb(c)),a=c),a}function x(){var a,b,c,d,e,f;if(a=hd,(b=t())!==Y){for(c=[],d=hd,e=O(),e!==Y?(f=o(),f!==Y?(e=[e,f],d=e):(hd=d,d=Y)):(hd=d,d=Y);d!==Y;)c.push(d),d=hd,e=O(),e!==Y?(f=o(),f!==Y?(e=[e,f],d=e):(hd=d,d=Y)):(hd=d,d=Y);c!==Y?(id=a,b=rb(b,c),a=b):(hd=a,a=Y)}else hd=a,a=Y;return a}function y(){var a,c,d,f,g,h,i,j;if(a=hd,(c=z())!==Y){for(d=[],f=hd,g=O(),g!==Y?(b.substr(hd,2)===sb?(h=sb,hd+=2):(h=Y,0===md&&e(tb)),h!==Y?(i=O(),i!==Y?(j=z(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(b.substr(hd,2)===sb?(h=sb,hd+=2):(h=Y,0===md&&e(tb)),h!==Y?(i=O(),i!==Y?(j=z(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function z(){var a,c,d,f,g,h,i,j;if(a=hd,(c=A())!==Y){for(d=[],f=hd,g=O(),g!==Y?(b.substr(hd,3)===ub?(h=ub,hd+=3):(h=Y,0===md&&e(vb)),h!==Y?(i=O(),i!==Y?(j=A(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(b.substr(hd,3)===ub?(h=ub,hd+=3):(h=Y,0===md&&e(vb)),h!==Y?(i=O(),i!==Y?(j=A(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function A(){var a,c,d,f,g,h,i,j;if(a=hd,(c=B())!==Y){for(d=[],f=hd,g=O(),g!==Y?(61===b.charCodeAt(hd)?(h=wb,hd++):(h=Y,0===md&&e(xb)),h===Y&&(b.substr(hd,2)===yb?(h=yb,hd+=2):(h=Y,0===md&&e(zb))),h!==Y?(i=O(),i!==Y?(j=B(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(61===b.charCodeAt(hd)?(h=wb,hd++):(h=Y,0===md&&e(xb)),h===Y&&(b.substr(hd,2)===yb?(h=yb,hd+=2):(h=Y,0===md&&e(zb))),h!==Y?(i=O(),i!==Y?(j=B(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function B(){var a,c,d,f,g,h,i,j;if(a=hd,(c=C())!==Y){for(d=[],f=hd,g=O(),g!==Y?(b.substr(hd,2)===Ab?(h=Ab,hd+=2):(h=Y,0===md&&e(Bb)),h===Y&&(60===b.charCodeAt(hd)?(h=Cb,hd++):(h=Y,0===md&&e(Db)),h===Y&&(b.substr(hd,2)===Eb?(h=Eb,hd+=2):(h=Y,0===md&&e(Fb)),h===Y&&(62===b.charCodeAt(hd)?(h=Gb,hd++):(h=Y,0===md&&e(Hb))))),h!==Y?(i=O(),i!==Y?(j=C(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(b.substr(hd,2)===Ab?(h=Ab,hd+=2):(h=Y,0===md&&e(Bb)),h===Y&&(60===b.charCodeAt(hd)?(h=Cb,hd++):(h=Y,0===md&&e(Db)),h===Y&&(b.substr(hd,2)===Eb?(h=Eb,hd+=2):(h=Y,0===md&&e(Fb)),h===Y&&(62===b.charCodeAt(hd)?(h=Gb,hd++):(h=Y,0===md&&e(Hb))))),h!==Y?(i=O(),i!==Y?(j=C(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function C(){var a,c,d,f,g,h,i,j;if(a=hd,(c=D())!==Y){for(d=[],f=hd,g=O(),g!==Y?(43===b.charCodeAt(hd)?(h=Ib,hd++):(h=Y,0===md&&e(Jb)),h===Y&&(45===b.charCodeAt(hd)?(h=Kb,hd++):(h=Y,0===md&&e(Lb))),h!==Y?(i=O(),i!==Y?(j=D(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(43===b.charCodeAt(hd)?(h=Ib,hd++):(h=Y,0===md&&e(Jb)),h===Y&&(45===b.charCodeAt(hd)?(h=Kb,hd++):(h=Y,0===md&&e(Lb))),h!==Y?(i=O(),i!==Y?(j=D(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function D(){var a,c,d,f,g,h,i,j;if(a=hd,(c=E())!==Y){for(d=[],f=hd,g=O(),g!==Y?(h=I(),h===Y&&(b.substr(hd,3)===Mb?(h=Mb,hd+=3):(h=Y,0===md&&e(Nb)),h===Y&&(b.substr(hd,3)===Ob?(h=Ob,hd+=3):(h=Y,0===md&&e(Pb)))),h!==Y?(i=O(),i!==Y?(j=E(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);f!==Y;)d.push(f),f=hd,g=O(),g!==Y?(h=I(),h===Y&&(b.substr(hd,3)===Mb?(h=Mb,hd+=3):(h=Y,0===md&&e(Nb)),h===Y&&(b.substr(hd,3)===Ob?(h=Ob,hd+=3):(h=Y,0===md&&e(Pb)))),h!==Y?(i=O(),i!==Y?(j=E(),j!==Y?(g=[g,h,i,j],f=g):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y)):(hd=f,f=Y);d!==Y?(id=a,c=ob(c,d),a=c):(hd=a,a=Y)}else hd=a,a=Y;return a}function E(){var a,c,d,f;return a=hd,c=v(),c!==Y&&(id=a,c=Ya(c)),a=c,a===Y&&(a=hd,45===b.charCodeAt(hd)?(c=Kb,hd++):(c=Y,0===md&&e(Lb)),c!==Y?(d=O(),d!==Y?(f=E(),f!==Y?(id=a,c=Qb(f),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y)),a}function F(){var a,c,d,f;if(a=hd,34===b.charCodeAt(hd)?(c=Rb,hd++):(c=Y,0===md&&e(Sb)),c!==Y){for(d=[],Tb.test(b.charAt(hd))?(f=b.charAt(hd),hd++):(f=Y,0===md&&e(Ub));f!==Y;)d.push(f),Tb.test(b.charAt(hd))?(f=b.charAt(hd),hd++):(f=Y,0===md&&e(Ub));d!==Y?(34===b.charCodeAt(hd)?(f=Rb,hd++):(f=Y,0===md&&e(Sb)),f!==Y?(id=a,c=Vb(d),a=c):(hd=a,a=Y)):(hd=a,a=Y)}else hd=a,a=Y;if(a===Y)if(a=hd,39===b.charCodeAt(hd)?(c=Wb,hd++):(c=Y,0===md&&e(Xb)),c!==Y){for(d=[],Yb.test(b.charAt(hd))?(f=b.charAt(hd),hd++):(f=Y,0===md&&e(Zb));f!==Y;)d.push(f),Yb.test(b.charAt(hd))?(f=b.charAt(hd),hd++):(f=Y,0===md&&e(Zb));d!==Y?(39===b.charCodeAt(hd)?(f=Wb,hd++):(f=Y,0===md&&e(Xb)),f!==Y?(id=a,c=Vb(d),a=c):(hd=a,a=Y)):(hd=a,a=Y)}else hd=a,a=Y;return a}function G(){var a,c,d,f,g;return a=hd,c=H(),c!==Y?(d=hd,46===b.charCodeAt(hd)?(f=ab,hd++):(f=Y,0===md&&e(bb)),f!==Y?(g=H(),g===Y&&(g=null),g!==Y?(f=[f,g],d=f):(hd=d,d=Y)):(hd=d,d=Y),d===Y&&(d=null),d!==Y?(id=a,c=$b(c,d),a=c):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,46===b.charCodeAt(hd)?(c=ab,hd++):(c=Y,0===md&&e(bb)),c!==Y?(d=H(),d!==Y?(id=a,c=_b(d),a=c):(hd=a,a=Y)):(hd=a,a=Y)),a}function H(){var a,c,d;if(a=hd,c=[],ac.test(b.charAt(hd))?(d=b.charAt(hd),hd++):(d=Y,0===md&&e(bc)),d!==Y)for(;d!==Y;)c.push(d),ac.test(b.charAt(hd))?(d=b.charAt(hd),hd++):(d=Y,0===md&&e(bc));else c=Y;return c!==Y&&(id=a,c=cc(c)),a=c}function I(){var a;return 42===b.charCodeAt(hd)?(a=dc,hd++):(a=Y,0===md&&e(ec)),a}function J(){var a,b,c;return a=hd,b=P(),b!==Y?(id=hd,c=fc(b),c=c?void 0:Y,c!==Y?(id=a,b=gc(b),a=b):(hd=a,a=Y)):(hd=a,a=Y),a}function K(){var a,c,d;return a=hd,36===b.charCodeAt(hd)?(c=hc,hd++):(c=Y,0===md&&e(ic)),c!==Y?(d=P(),d!==Y?(id=a,c=jc(d),a=c):(hd=a,a=Y)):(hd=a,a=Y),a}function L(){var a,c,d,f;return a=hd,42===b.charCodeAt(hd)?(c=dc,hd++):(c=Y,0===md&&e(ec)),c!==Y&&(id=a,c=kc()),a=c,a===Y&&(a=hd,c=S(),c!==Y?(58===b.charCodeAt(hd)?(d=lc,hd++):(d=Y,0===md&&e(mc)),d!==Y?(42===b.charCodeAt(hd)?(f=dc,hd++):(f=Y,0===md&&e(ec)),f!==Y?(id=a,c=nc(c),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a===Y&&(a=hd,c=P(),c!==Y&&(id=a,c=oc(c)),a=c)),a}function M(){var a;return b.substr(hd,7)===pc?(a=pc,hd+=7):(a=Y,0===md&&e(qc)),a===Y&&(b.substr(hd,4)===rc?(a=rc,hd+=4):(a=Y,0===md&&e(sc)),a===Y&&(b.substr(hd,22)===Qa?(a=Qa,hd+=22):(a=Y,0===md&&e(Ra)),a===Y&&(b.substr(hd,4)===tc?(a=tc,hd+=4):(a=Y,0===md&&e(uc))))),a}function N(){var a,c;if(a=[],vc.test(b.charAt(hd))?(c=b.charAt(hd),hd++):(c=Y,0===md&&e(wc)),c!==Y)for(;c!==Y;)a.push(c),vc.test(b.charAt(hd))?(c=b.charAt(hd),hd++):(c=Y,0===md&&e(wc));else a=Y;return a}function O(){var a;return a=N(),a===Y&&(a=null),a}function P(){var a,b;return a=hd,b=Q(),b===Y&&(b=R()),b!==Y&&(id=a,b=xc(b)),a=b}function Q(){var a,c,d,f;return a=hd,c=S(),c!==Y?(58===b.charCodeAt(hd)?(d=lc,hd++):(d=Y,0===md&&e(mc)),d!==Y?(f=S(),f!==Y?(id=a,c=yc(c,f),a=c):(hd=a,a=Y)):(hd=a,a=Y)):(hd=a,a=Y),a}function R(){var a,b;return a=hd,b=S(),b!==Y&&(id=a,b=zc(b)),a=b}function S(){return V()}function T(){var a;return Ac.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Bc)),a===Y&&(95===b.charCodeAt(hd)?(a=Cc,hd++):(a=Y,0===md&&e(Dc)),a===Y&&(Ec.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Fc)),a===Y&&(Gc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Hc)),a===Y&&(Ic.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Jc)),a===Y&&(Kc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Lc)),a===Y&&(Mc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Nc)),a===Y&&(Oc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Pc)),a===Y&&(Qc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Rc)),a===Y&&(Sc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Tc)),a===Y&&(Uc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Vc)),a===Y&&(Wc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Xc)),a===Y&&(Yc.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(Zc)),a===Y&&($c.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(_c))))))))))))))),a}function U(){var a;return a=T(),a===Y&&(45===b.charCodeAt(hd)?(a=Kb,hd++):(a=Y,0===md&&e(Lb)),a===Y&&(46===b.charCodeAt(hd)?(a=ab,hd++):(a=Y,0===md&&e(bb)),a===Y&&(ac.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(bc)),a===Y&&(ad.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(bd)),a===Y&&(cd.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(dd)),a===Y&&(ed.test(b.charAt(hd))?(a=b.charAt(hd),hd++):(a=Y,0===md&&e(fd)))))))),a}function V(){var a,b,c,d;if(a=hd,(b=T())!==Y){for(c=[],d=U();d!==Y;)c.push(d),d=U();c!==Y?(id=a,b=gd(b,c),a=b):(hd=a,a=Y)}else hd=a,a=Y;return a}var W,X=arguments.length>1?arguments[1]:{},Y={},Z={XPath:g},$=g,_=function(a){return{tree:a,nsPrefixes:qd}},aa="/",ba={type:"literal",value:"/",description:'"/"'},ca=function(a){return{type:"/",args:[null,a?a[1]:null]}},da="//",ea={type:"literal",value:"//",description:'"//"'},fa=function(a,b){var c;for(c=0;c=",Fb={type:"literal",value:">=",description:'">="'},Gb=">",Hb={type:"literal",value:">",description:'">"'},Ib="+",Jb={type:"literal",value:"+",description:'"+"'},Kb="-",Lb={type:"literal",value:"-",description:'"-"'},Mb="div",Nb={type:"literal",value:"div",description:'"div"'},Ob="mod",Pb={type:"literal",value:"mod",description:'"mod"'},Qb=function(a){return{type:"*",args:[{type:"number",args:[-1]},a]}},Rb='"',Sb={type:"literal",value:'"',description:'"\\""'},Tb=/^[^"]/,Ub={type:"class",value:'[^"]',description:'[^"]'},Vb=function(a){return{type:"string",args:[a.join("")]}},Wb="'",Xb={type:"literal",value:"'",description:'"\'"'},Yb=/^[^']/,Zb={type:"class",value:"[^']",description:"[^']"},$b=function(a,b){return{type:"number",args:[b?parseFloat(a+"."+b[1]):parseInt(a)]}},_b=function(a){return{type:"number",args:[parseFloat("."+a)]}},ac=/^[0-9]/,bc={type:"class",value:"[0-9]",description:"[0-9]"},cc=function(a){return a.join("")},dc="*",ec={type:"literal",value:"*",description:'"*"'},fc=function(a){var b;if(null===nd.args[0])for(b=0;b1&&n[0].compareDocumentPosition&&n.sort(function(e,t){var n=e.compareDocumentPosition(t);return 2==(2&n)?1:4==(4&n)?-1:0}),n},F=function(e){var t,n=P(e),r=[];for(t=0;t=0;r--)i=e.ownerDocument.namespaces.item(r),M.call(this,s,i.name,i.urn,e);for(r=(n=P(e)).length-1;r>=0;r--)!1!==(o=I(n[r]))&&(1!==o.length?M.call(this,s,o[1],n[r].nodeValue,e):M.call(this,s,"",n[r].nodeValue,e));if(C.call(this,e.parentNode,s),void 0===t&&(M.call(this,s,"xml",y,e),s[0]&&""===s[0].prefix&&""===s[0].namespaceURI&&s.shift()),void 0===t)for(r=0;r=0&&r.sourceIndex>=0?(n.sourceIndexr.sourceIndex&&2):1)+0}if(e===n&&t===r)return o;if(e===n)return a(0,0,0,0,o,16,8,4,2);if(t===r)return a(0,0,0,0,o,8,16,2,4);if(16==(16&o))return 4;if(8==(8&o))return 2;if(0===o){for(i=0;i0},g.prototype.toString=function(){return this.value.length<1?"":(this.sortDocumentOrder(),X(this.value[0]))},g.prototype.toNumber=function(){return new h(this.toString()).toNumber()},g.prototype.toNodeSet=function(){return this.value},g.prototype.toDate=function(){return new h(this.toString()).toDate()},g.prototype.sortDocumentOrder=function(){switch(this.docOrder){case"document-order":break;case"reverse-document-order":this.value.reverse();break;default:this.value.sort(function(e,t){var n=H(e,t);if(4==(4&n))return-1;if(2==(2&n))return 1;throw new Error("NodeSetType.sortDocumentOrder - unexpected compare result: "+n)})}this.docOrder="document-order"},g.prototype.sortReverseDocumentOrder=function(){switch(this.docOrder){case"document-order":this.value.reverse();break;case"reverse-document-order":break;default:this.sortDocumentOrder(),this.value.reverse()}this.docOrder="reverse-document-order"},g.prototype.append=function(e){var t,n=0,r=0;if(!e instanceof g)throw new Error("NodeSetType can be passed into NodeSetType.append method");for(this.sortDocumentOrder(),e.sortDocumentOrder();n0},h.prototype.toString=function(){return this.value},h.prototype.toNumber=function(){var e;return this.isDateString(this.value)?new DateType(this.value).toNumber():null!==(e=this.value.match(/^[ \t\r\n]*(-?[0-9]+(?:[.][0-9]*)?)[ \t\r\n]*$/))?parseFloat(e[1]):(e=this.value.match(/^[ \t\r\n]*(-?[.][0-9]+)[ \t\r\n]*$/),null!==e?parseFloat(e[1]):Number.NaN)},h.prototype.toDate=function(){return new Date(this.value)},h.prototype.isDateString=function(){return!!isNaN(this.value)&&(!isNaN(Date.parse(this.value))&&!!/('|")?[0-9]{4}(-|\/)[0-9]{2}(-|\/)[0-9]{2}('|")?/.test(this.value))},d=function(e){p.call(this,e,"number",["boolean","string","number","date"])},d.prototype=new p,d.constructor=d,d.prototype.toBoolean=function(){return 0!==this.value&&!isNaN(this.value)},d.prototype.toString=function(){return this.value.toString()},d.prototype.toNumber=function(){return this.value},d.prototype.toDate=function(){return new Date(864e5*this.value)},DateType=function(e){p.call(this,e,"date",["date","string","number","boolean"])},DateType.prototype=new p,DateType.constructor=DateType,DateType.prototype.toDate=function(){return new Date(this.value)},DateType.prototype.toString=function(){return new Date(this.value).toUTCString()},DateType.prototype.toNumber=function(){return new Date(this.value).getTime()/864e5},DateType.prototype.toBoolean=function(){return!isNaN(new Date(this.value).getTime())},e=function(t,n){var r;switch(this.code=t,this.code){case e.INVALID_EXPRESSION_ERR:this.name="INVALID_EXPRESSION_ERR";break;case e.TYPE_ERR:this.name="TYPE_ERR";break;default:throw r=new Error("Unsupported XPathException code: "+this.code),r.name="XPathExceptionInternalError",r}this.message=n||""},e.prototype.toString=function(){return'XPathException: "'+this.message+'", code: "'+this.code+'", name: "'+this.name+'"'},e.INVALID_EXPRESSION_ERR=51,e.TYPE_ERR=52,t=function(e){var t,n,r;for(t in e){r=!1;for(n in this.opts)if(t===n){this.opts[t]=e[t],r=!0;break}if(!r)throw new Error("Unsupported option: "+t)}this.opts["unique-ids"][y]="id",this.opts["unique-ids"]["http://www.w3.org/1999/xhtml"]="id"},t.prototype={opts:{"unique-ids":{},"case-sensitive":!1},createExpression:function(t,r){var o,i,s,a,u={};try{o=XPathJS._parser.parse(t)}catch(t){throw i="The expression is not a legal expression.",t instanceof XPathJS._parser.SyntaxError?i+=" (line: "+t.line+", character: "+t.column+")":i+=" ("+t.message+")",new e(e.INVALID_EXPRESSION_ERR,i)}if(o.nsPrefixes.length>0){if("object"!=typeof r||void 0===r.lookupNamespaceURI)throw new e(e.INVALID_EXPRESSION_ERR,"No namespace resolver provided or lookupNamespaceURI function not supported.");for(s=0;s=0;r--)switch(t.args[0]){case"text":3!=n.value[r].nodeType&&4!=n.value[r].nodeType&&n.value.splice(r,1);break;case"comment":8!=n.value[r].nodeType&&n.value.splice(r,1);break;case"processing-instruction":(7!=n.value[r].nodeType||t.args[1].length>0&&a(this,t.args[1][0])!=n.value[r].nodeName)&&n.value.splice(r,1)}break;case"name":switch(s=a(this,t),e){case"attribute":u=2;break;case"namespace":u=13;break;default:u=1}for(r=n.value.length-1;r>=0;r--)n.value[r].nodeType==u?null===s.ns&&null===s.name||(!1!==(c=B.call(this,n.value[r]))&&c.ns===s.ns?null!==s.name&&c.name.toLowerCase()!=s.name.toLowerCase()&&n.value.splice(r,1):n.value.splice(r,1)):n.value.splice(r,1);break;default:throw new Error("NodeTest type not supported in step: "+t.type)}return n},predicate:function(e,t,n){var r,o,i,s,u,c;if(!(r=a(this,t))instanceof g)throw new Error('Expected "node-set", got: '+r.type);switch(e){case"ancestor":case"ancestor-or-self":case"preceding":case"preceding-sibling":r.sortReverseDocumentOrder();break;default:r.sortDocumentOrder()}for(s=0;s=":function(e,t){return V.call(this,a(this,e),a(this,t),">=",function(e,t){return e>=t})},">":function(e,t){return V.call(this,a(this,e),a(this,t),">",function(e,t){return e>t})},"+":function(e,t){return new d(a(this,e).toNumber()+a(this,t).toNumber())},"-":function(e,t){return new d(a(this,e).toNumber()-a(this,t).toNumber())},div:function(e,t){return new d(a(this,e).toNumber()/a(this,t).toNumber())},mod:function(e,t){return new d(a(this,e).toNumber()%a(this,t).toNumber())},"*":function(e,t){return new d(a(this,e).toNumber()*a(this,t).toNumber())},string:function(e){return new h(e)},number:function(e){return new d(e)},$:function(e){throw new Error("TODO: Not implemented.16")},name:function(e,t){var n=null;if(null!==e&&!(n=this.nsMap[e]))throw new Error('Namespace prefix "'+e+'" is not mapped to a namespace.');return{ns:n,name:t}}},c={"":{last:{fn:function(){return new d(this.size)},ret:"number"},count:{fn:function(e){return new d(e.toNodeSet().length)},args:[{t:"node-set"}],ret:"number"},id:{fn:function(e){var t,n,r,o=this,i=[],s=[],a=function(e){var t,n=e.split(/[\u0020\u0009\u000D\u000A]+/);for(t=n.length-1;t>=0;t--)0==n[t].length&&n.splice(t,1);return n};if(e instanceof g)for(t=0;t=0;t--)for(n=t-1;n>=0;n--)if(i[t]==i[n]&&t!=n){i.splice(t,1);break}for(t=0;t0&&(e.sortDocumentOrder(),!1!==(t=B.call(this,e.value[0]))&&(n=t.name)),new h(n)},args:[{t:"node-set",r:!1}],ret:"string"},"namespace-uri":{fn:function(e){var t,n="";return 0==arguments.length&&(e=new g([this.node])),e.toNodeSet().length>0&&(e.sortDocumentOrder(),!1!==(t=B.call(this,e.value[0]))&&null!==t.ns&&(n=t.ns)),new h(n)},args:[{t:"node-set",r:!1}],ret:"string"},name:{fn:function(e){var t,n="";return 0==arguments.length&&(e=new g([this.node])),e.toNodeSet().length>0&&(e.sortDocumentOrder(),!1!==(t=B.call(this,e.value[0]))&&(n=t.prefix&&t.prefix.length>0?t.prefix+":"+t.name:t.name)),new h(n)},args:[{t:"node-set",r:!1}],ret:"string"},string:{fn:function(e){return 0==arguments.length&&(e=new g([this.node],"document-order")),new h(e.toString())},args:[{t:"object",r:!1}],ret:"string"},"starts-with":{fn:function(e,t){return new f(e.toString().substr(0,(t=t.toString()).length)==t)},args:[{t:"string"},{t:"string"}],ret:"string"},contains:{fn:function(e,t){return new f(-1!=e.toString().indexOf(t=t.toString()))},args:[{t:"string"},{t:"string"}],ret:"string"},"substring-before":{fn:function(e,t){return e=e.toString(),t=e.indexOf(t.toString()),new h(-1==t?"":e.substr(0,t))},args:[{t:"string"},{t:"string"}],ret:"string"},"substring-after":{fn:function(e,t){var n;return e=e.toString(),t=t.toString(),n=e.indexOf(t),new h(-1==n?"":e.substr(n+t.length))},args:[{t:"string"},{t:"string"}],ret:"string"},substring:{fn:function(e,t,n){return e=e.toString(),t=Math.round(t.toNumber())-1,new h(isNaN(t)?"":2==arguments.length?e.substring(t<0?0:t):e.substring(t<0?0:t,t+Math.round(n.toNumber())))},args:[{t:"string"},{t:"number"},{t:"number",r:!1}],ret:"string"},"string-length":{fn:function(e){return e=0==arguments.length?X(this.node):e.toString(),new d(e.length)},args:[{t:"string",r:!1}],ret:"number"},"normalize-space":{fn:function(e){return e=0==arguments.length?X(this.node):e.toString(),new h(e.replace(/^[\u0020\u0009\u000D\u000A]+/,"").replace(/[\u0020\u0009\u000D\u000A]+$/,"").replace(/[\u0020\u0009\u000D\u000A]+/g," "))},args:[{t:"string",r:!1}],ret:"string"},translate:{fn:function(e,t,n){var r,o,i,s="";for(e=e.toString(),t=t.toString(),n=n.toString(),r=0;r0&&n++;return new d(n)},args:[{t:"node-set"}],ret:"number"},position:{fn:function(e){if(e){var t,n,r;if(1===(e=e.toNodeSet()).length){for(r=1,n=(t=e[0]).tagName;t.previousElementSibling&&t.previousElementSibling.tagName===n;)t=t.previousElementSibling,r++;return new d(r)}throw new Error("nodeset provided to position() contained multiple nodes")}return new d(this.pos)},args:[{t:"node-set",r:!1}],ret:"number"},concat:{fn:function(e){var t,n="";for(t=0;t=0&&t0?(t=X(e[0]).trim().split(" "),new d(1==t.length&&""===t[0]?0:t.length)):new d(0)},args:[{t:"node-set"}],ret:"number"},checklist:{fn:function(e,t,n){var r,o,i=0;for(e=e.toNumber(),t=t.toNumber(),r=2;r=e)&&(t<0||i<=t))},args:[{t:"number"},{t:"number"},{t:"object"},{t:"object",r:!1,rep:!0}],ret:"boolean"},"weighted-checklist":{fn:function(e,t,n,r){var o,i=[],s=[],a=0;for(e=e.toNumber(),t=t.toNumber(),o=2;o=e)&&(t<0||a<=t))},args:[{t:"number"},{t:"number"},{t:"object"},{t:"object"},{t:"object",r:!1,rep:!0}],ret:"boolean"},"boolean-from-string":{fn:function(e){return new f("true"===e.toString().toLowerCase()||"1"===String(e))},args:[{t:"string"}],ret:"boolean"},if:{fn:function(e,t,n){return e.toBoolean()?t:n},args:[{t:"object"},{t:"object"},{t:"object"}],ret:"object"},date:{fn:function(e){return new DateType(e.toDate())},args:[{t:"object"}],ret:"string"},"date-time":{fn:function(e){return new DateType(e.toDate())},args:[{t:"object"}],ret:"string"},"decimal-date-time":{fn:function(e){return new DateType(e.toDate())},args:[{t:"object"}],ret:"string"},today:{fn:function(){var e=new Date;return new DateType(new Date(e.getFullYear(),e.getMonth(),e.getDate()))},ret:"string"},now:{fn:function(){return new DateType(new Date)},ret:"string"},regex:{fn:function(e,t){var n,r;return n=e.toString(),r=new RegExp(t),new f(r.test(n))},args:[{t:"object"},{t:"string"}],ret:"boolean"},uuid:{fn:function(){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)});return new h(e)},ret:"string"},int:{fn:function(e){return new d(e.toNumber()>=0?Math.floor(e.toNumber()):-Math.floor(Math.abs(e.toNumber())))},args:[{t:"string"}],ret:"number"},substr:{fn:function(e,t,n){return e=e.toString(),length=e.length,t=Math.round(t.toNumber()),n=n?Math.round(n.toNumber()):length,new h(isNaN(t)?"":e.substring(t<0?length+t:t,n<0?length+n:n))},args:[{t:"string"},{t:"number"},{t:"number",r:!1}],ret:"string"},random:{fn:function(){return new d(Math.random().toFixed(15))},ret:"number"},min:{fn:function(e,t){var n,r,o,i,s;for(n=0;n0?e:t},args:[{t:"object"},{t:"object"}],ret:"string"},"format-date":{fn:function(e,t){var n,r=(e=new DateType(e)).toDate(),o=t.toString(),i=function(e,t){var r=e.toString(),o=t-r.length;for(n=0;n1?e.value.forEach(function(e){n.push(X(e))}):e instanceof g?n=X(e.value[0]).split(";"):e instanceof h&&(n=e.value.split(";")),r=n.map(function(e){return e.trim().split(" ")}),r.every(function(e){return""!==e[0]&&e[0]>=-90&&e[0]<=90&&""!==e[1]&&e[1]>=-180&&e[1]<=180&&(void 0===e[2]||!isNaN(e[2]))&&(void 0===e[3]||!isNaN(e[3])&&e[3]>=0)})){var o,i,s=r.length,a=Math.PI/180;if(t=0,s>2){for(var u=0;upr&&(pr=ur,fr=[]),fr.push(e))}function i(t,n,r,o){return null!==n&&function(e){var t=1;for(e.sort(function(e,t){return e.descriptiont.description?1:0});t1?i.slice(0,-1).join(", ")+" or "+i[e.length-1]:i[0],r=t?'"'+function(e){function t(e){return e.charCodeAt(0).toString(16).toUpperCase()}return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(e){return"\\x0"+t(e)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(e){return"\\x"+t(e)}).replace(/[\u0100-\u0FFF]/g,function(e){return"\\u0"+t(e)}).replace(/[\u1000-\uFFFF]/g,function(e){return"\\u"+t(e)})}(t)+'"':"end of input","Expected "+n+" but "+r+" found."}(n,r),n,r,o)}function s(){var e,t,n;return e=ur,t=U(),t!==Z&&(n=w())!==Z&&U()!==Z?(cr=e,e=t=Q(n)):(ur=e,e=Z),e}function a(){var e;return(e=c())===Z&&(e=u()),e}function u(){var e,n,r,i,s;return(e=g())===Z&&(e=ur,47===t.charCodeAt(ur)?(n=ee,ur++):(n=Z,0===hr&&o(te)),n!==Z?(r=ur,(i=U())!==Z&&(s=c())!==Z?r=i=[i,s]:(ur=r,r=Z),r===Z&&(r=null),r!==Z?(cr=e,e=n=ne(r)):(ur=e,e=Z)):(ur=e,e=Z)),e}function c(){var e,n,r,i,s,a,u,c;if(e=ur,(n=l())!==Z){for(r=[],i=ur,(s=U())!==Z?(t.substr(ur,2)===re?(a=re,ur+=2):(a=Z,0===hr&&o(oe)),a===Z&&(47===t.charCodeAt(ur)?(a=ee,ur++):(a=Z,0===hr&&o(te))),a!==Z&&(u=U())!==Z&&(c=l())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(t.substr(ur,2)===re?(a=re,ur+=2):(a=Z,0===hr&&o(oe)),a===Z&&(47===t.charCodeAt(ur)?(a=ee,ur++):(a=Z,0===hr&&o(te))),a!==Z&&(u=U())!==Z&&(c=l())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=ie(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function l(){var e,t,n,r,o,i,s;if(e=ur,(t=p())!==Z)if(U()!==Z)if((n=h())!==Z){for(r=[],o=ur,(i=U())!==Z&&(s=d())!==Z?o=i=[i,s]:(ur=o,o=Z);o!==Z;)r.push(o),o=ur,(i=U())!==Z&&(s=d())!==Z?o=i=[i,s]:(ur=o,o=Z);r!==Z?(cr=e,e=t=se(t,n,r)):(ur=e,e=Z)}else ur=e,e=Z;else ur=e,e=Z;else ur=e,e=Z;return e===Z&&(e=m()),e}function p(){var e,n,r;return e=ur,n=f(),n!==Z&&U()!==Z?(t.substr(ur,2)===ae?(r=ae,ur+=2):(r=Z,0===hr&&o(ue)),r!==Z?(cr=e,e=n=ce(n)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,(n=v())!==Z&&(cr=e,n=le(n)),e=n),e}function f(){var e;return t.substr(ur,16)===pe?(e=pe,ur+=16):(e=Z,0===hr&&o(fe)),e===Z&&(t.substr(ur,8)===he?(e=he,ur+=8):(e=Z,0===hr&&o(de)),e===Z&&(t.substr(ur,9)===ge?(e=ge,ur+=9):(e=Z,0===hr&&o(me)),e===Z&&(t.substr(ur,5)===ve?(e=ve,ur+=5):(e=Z,0===hr&&o(we)),e===Z&&(t.substr(ur,18)===be?(e=be,ur+=18):(e=Z,0===hr&&o(ye)),e===Z&&(t.substr(ur,10)===Ee?(e=Ee,ur+=10):(e=Z,0===hr&&o(Ne)),e===Z&&(t.substr(ur,17)===De?(e=De,ur+=17):(e=Z,0===hr&&o(Te)),e===Z&&(t.substr(ur,9)===xe?(e=xe,ur+=9):(e=Z,0===hr&&o(Re)),e===Z&&(t.substr(ur,9)===Se?(e=Se,ur+=9):(e=Z,0===hr&&o(Ae)),e===Z&&(t.substr(ur,6)===_e?(e=_e,ur+=6):(e=Z,0===hr&&o(Oe)),e===Z&&(t.substr(ur,17)===Pe?(e=Pe,ur+=17):(e=Z,0===hr&&o(Fe)),e===Z&&(t.substr(ur,9)===Ce?(e=Ce,ur+=9):(e=Z,0===hr&&o(Me)),e===Z&&(t.substr(ur,4)===Ie?(e=Ie,ur+=4):(e=Z,0===hr&&o(Ye)))))))))))))),e}function h(){var e,n,r,i,s;return e=ur,n=B(),n!==Z&&U()!==Z?(40===t.charCodeAt(ur)?(r=ke,ur++):(r=Z,0===hr&&o(Be)),r!==Z&&U()!==Z?(41===t.charCodeAt(ur)?(i=Xe,ur++):(i=Z,0===hr&&o(Ue)),i!==Z?(cr=e,e=n=je(n)):(ur=e,e=Z)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,t.substr(ur,22)===Ve?(n=Ve,ur+=22):(n=Z,0===hr&&o(Le)),n!==Z&&U()!==Z?(40===t.charCodeAt(ur)?(r=ke,ur++):(r=Z,0===hr&&o(Be)),r!==Z&&U()!==Z&&(i=P())!==Z&&U()!==Z?(41===t.charCodeAt(ur)?(s=Xe,ur++):(s=Z,0===hr&&o(Ue)),s!==Z?(cr=e,e=n=He(n,i)):(ur=e,e=Z)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,(n=k())!==Z&&(cr=e,n=Je(n)),e=n)),e}function d(){var e,n,r,i;return e=ur,91===t.charCodeAt(ur)?(n=ze,ur++):(n=Z,0===hr&&o($e)),n!==Z&&U()!==Z&&(r=w())!==Z&&U()!==Z?(93===t.charCodeAt(ur)?(i=qe,ur++):(i=Z,0===hr&&o(Ge)),i!==Z?(cr=e,e=n=Ze(r)):(ur=e,e=Z)):(ur=e,e=Z),e}function g(){var e,n,r;return e=ur,t.substr(ur,2)===re?(n=re,ur+=2):(n=Z,0===hr&&o(oe)),n!==Z&&U()!==Z&&(r=c())!==Z?(cr=e,e=n=We(r)):(ur=e,e=Z),e}function m(){var e,n;return e=ur,t.substr(ur,2)===Ke?(n=Ke,ur+=2):(n=Z,0===hr&&o(Qe)),n===Z&&(46===t.charCodeAt(ur)?(n=et,ur++):(n=Z,0===hr&&o(tt))),n!==Z&&(cr=e,n=nt(n)),e=n}function v(){var e,n;return e=ur,64===t.charCodeAt(ur)?(n=rt,ur++):(n=Z,0===hr&&o(ot)),n===Z&&(n=null),n!==Z&&(cr=e,n=it(n)),e=n}function w(){var e,t;return e=ur,(t=T())!==Z&&(cr=e,t=Ze(t)),e=t}function b(){var e,n,r,i;return e=ur,(n=Y())!==Z&&(cr=e,n=st(n)),(e=n)===Z&&(e=ur,40===t.charCodeAt(ur)?(n=ke,ur++):(n=Z,0===hr&&o(Be)),n!==Z&&U()!==Z&&(r=w())!==Z&&U()!==Z?(41===t.charCodeAt(ur)?(i=Xe,ur++):(i=Z,0===hr&&o(Ue)),i!==Z?(cr=e,e=n=Ze(r)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,(n=P())!==Z&&(cr=e,n=at(n)),(e=n)===Z&&(e=ur,(n=F())!==Z&&(cr=e,n=ut(n)),(e=n)===Z&&(e=y())))),e}function y(){var e,n,r,i,s,a,u,c,l,p,f,h;if(e=ur,(n=I())!==Z)if(U()!==Z)if(40===t.charCodeAt(ur)?(r=ke,ur++):(r=Z,0===hr&&o(Be)),r!==Z){if(i=ur,(s=U())!==Z)if((a=w())!==Z){for(u=[],c=ur,(l=U())!==Z?(44===t.charCodeAt(ur)?(p=ct,ur++):(p=Z,0===hr&&o(lt)),p!==Z&&(f=U())!==Z&&(h=w())!==Z?c=l=[l,p,f,h]:(ur=c,c=Z)):(ur=c,c=Z);c!==Z;)u.push(c),c=ur,(l=U())!==Z?(44===t.charCodeAt(ur)?(p=ct,ur++):(p=Z,0===hr&&o(lt)),p!==Z&&(f=U())!==Z&&(h=w())!==Z?c=l=[l,p,f,h]:(ur=c,c=Z)):(ur=c,c=Z);u!==Z?i=s=[s,a,u]:(ur=i,i=Z)}else ur=i,i=Z;else ur=i,i=Z;i===Z&&(i=null),i!==Z&&(s=U())!==Z?(41===t.charCodeAt(ur)?(a=Xe,ur++):(a=Z,0===hr&&o(Ue)),a!==Z?(cr=e,e=n=pt(n,i)):(ur=e,e=Z)):(ur=e,e=Z)}else ur=e,e=Z;else ur=e,e=Z;else ur=e,e=Z;return e}function E(){var e,n,r,i,s,a,u,c;if(e=ur,(n=N())!==Z){for(r=[],i=ur,(s=U())!==Z?(124===t.charCodeAt(ur)?(a=ft,ur++):(a=Z,0===hr&&o(ht)),a!==Z&&(u=U())!==Z&&(c=N())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(124===t.charCodeAt(ur)?(a=ft,ur++):(a=Z,0===hr&&o(ht)),a!==Z&&(u=U())!==Z&&(c=N())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function N(){var e,n,r,i,s,u,l;return e=ur,n=D(),n!==Z?(r=ur,(i=U())!==Z?(t.substr(ur,2)===re?(s=re,ur+=2):(s=Z,0===hr&&o(oe)),s===Z&&(47===t.charCodeAt(ur)?(s=ee,ur++):(s=Z,0===hr&&o(te))),s!==Z&&(u=U())!==Z&&(l=c())!==Z?r=i=[i,s,u,l]:(ur=r,r=Z)):(ur=r,r=Z),r===Z&&(r=null),r!==Z?(cr=e,e=n=gt(n,r)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,(n=a())!==Z&&(cr=e,n=mt(n)),e=n),e}function D(){var e,t,n,r,o,i;if(e=ur,(t=b())!==Z){for(n=[],r=ur,(o=U())!==Z&&(i=d())!==Z?r=o=[o,i]:(ur=r,r=Z);r!==Z;)n.push(r),r=ur,(o=U())!==Z&&(i=d())!==Z?r=o=[o,i]:(ur=r,r=Z);n!==Z?(cr=e,e=t=vt(t,n)):(ur=e,e=Z)}else ur=e,e=Z;return e}function T(){var e,n,r,i,s,a,u,c;if(e=ur,(n=x())!==Z){for(r=[],i=ur,(s=U())!==Z?(t.substr(ur,2)===wt?(a=wt,ur+=2):(a=Z,0===hr&&o(bt)),a!==Z&&(u=U())!==Z&&(c=x())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(t.substr(ur,2)===wt?(a=wt,ur+=2):(a=Z,0===hr&&o(bt)),a!==Z&&(u=U())!==Z&&(c=x())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function x(){var e,n,r,i,s,a,u,c;if(e=ur,(n=R())!==Z){for(r=[],i=ur,(s=U())!==Z?(t.substr(ur,3)===yt?(a=yt,ur+=3):(a=Z,0===hr&&o(Et)),a!==Z&&(u=U())!==Z&&(c=R())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(t.substr(ur,3)===yt?(a=yt,ur+=3):(a=Z,0===hr&&o(Et)),a!==Z&&(u=U())!==Z&&(c=R())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function R(){var e,n,r,i,s,a,u,c;if(e=ur,(n=S())!==Z){for(r=[],i=ur,(s=U())!==Z?(61===t.charCodeAt(ur)?(a=Nt,ur++):(a=Z,0===hr&&o(Dt)),a===Z&&(t.substr(ur,2)===Tt?(a=Tt,ur+=2):(a=Z,0===hr&&o(xt))),a!==Z&&(u=U())!==Z&&(c=S())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(61===t.charCodeAt(ur)?(a=Nt,ur++):(a=Z,0===hr&&o(Dt)),a===Z&&(t.substr(ur,2)===Tt?(a=Tt,ur+=2):(a=Z,0===hr&&o(xt))),a!==Z&&(u=U())!==Z&&(c=S())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function S(){var e,n,r,i,s,a,u,c;if(e=ur,(n=A())!==Z){for(r=[],i=ur,(s=U())!==Z?(t.substr(ur,2)===Rt?(a=Rt,ur+=2):(a=Z,0===hr&&o(St)),a===Z&&(60===t.charCodeAt(ur)?(a=At,ur++):(a=Z,0===hr&&o(_t)),a===Z&&(t.substr(ur,2)===Ot?(a=Ot,ur+=2):(a=Z,0===hr&&o(Pt)),a===Z&&(62===t.charCodeAt(ur)?(a=Ft,ur++):(a=Z,0===hr&&o(Ct))))),a!==Z&&(u=U())!==Z&&(c=A())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(t.substr(ur,2)===Rt?(a=Rt,ur+=2):(a=Z,0===hr&&o(St)),a===Z&&(60===t.charCodeAt(ur)?(a=At,ur++):(a=Z,0===hr&&o(_t)),a===Z&&(t.substr(ur,2)===Ot?(a=Ot,ur+=2):(a=Z,0===hr&&o(Pt)),a===Z&&(62===t.charCodeAt(ur)?(a=Ft,ur++):(a=Z,0===hr&&o(Ct))))),a!==Z&&(u=U())!==Z&&(c=A())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function A(){var e,n,r,i,s,a,u,c;if(e=ur,(n=_())!==Z){for(r=[],i=ur,(s=U())!==Z?(43===t.charCodeAt(ur)?(a=Mt,ur++):(a=Z,0===hr&&o(It)),a===Z&&(45===t.charCodeAt(ur)?(a=Yt,ur++):(a=Z,0===hr&&o(kt))),a!==Z&&(u=U())!==Z&&(c=_())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?(43===t.charCodeAt(ur)?(a=Mt,ur++):(a=Z,0===hr&&o(It)),a===Z&&(45===t.charCodeAt(ur)?(a=Yt,ur++):(a=Z,0===hr&&o(kt))),a!==Z&&(u=U())!==Z&&(c=_())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function _(){var e,n,r,i,s,a,u,c;if(e=ur,(n=O())!==Z){for(r=[],i=ur,(s=U())!==Z?((a=M())===Z&&(t.substr(ur,3)===Bt?(a=Bt,ur+=3):(a=Z,0===hr&&o(Xt)),a===Z&&(t.substr(ur,3)===Ut?(a=Ut,ur+=3):(a=Z,0===hr&&o(jt)))),a!==Z&&(u=U())!==Z&&(c=O())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);i!==Z;)r.push(i),i=ur,(s=U())!==Z?((a=M())===Z&&(t.substr(ur,3)===Bt?(a=Bt,ur+=3):(a=Z,0===hr&&o(Xt)),a===Z&&(t.substr(ur,3)===Ut?(a=Ut,ur+=3):(a=Z,0===hr&&o(jt)))),a!==Z&&(u=U())!==Z&&(c=O())!==Z?i=s=[s,a,u,c]:(ur=i,i=Z)):(ur=i,i=Z);r!==Z?(cr=e,e=n=dt(n,r)):(ur=e,e=Z)}else ur=e,e=Z;return e}function O(){var e,n,r;return e=ur,(n=E())!==Z&&(cr=e,n=Ze(n)),(e=n)===Z&&(e=ur,45===t.charCodeAt(ur)?(n=Yt,ur++):(n=Z,0===hr&&o(kt)),n!==Z&&U()!==Z&&(r=O())!==Z?(cr=e,e=n=Vt(r)):(ur=e,e=Z)),e}function P(){var e,n,r,i;if(e=ur,34===t.charCodeAt(ur)?(n=Lt,ur++):(n=Z,0===hr&&o(Ht)),n!==Z){for(r=[],Jt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=Z,0===hr&&o(zt));i!==Z;)r.push(i),Jt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=Z,0===hr&&o(zt));r!==Z?(34===t.charCodeAt(ur)?(i=Lt,ur++):(i=Z,0===hr&&o(Ht)),i!==Z?(cr=e,e=n=$t(r)):(ur=e,e=Z)):(ur=e,e=Z)}else ur=e,e=Z;if(e===Z)if(e=ur,39===t.charCodeAt(ur)?(n=qt,ur++):(n=Z,0===hr&&o(Gt)),n!==Z){for(r=[],Zt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=Z,0===hr&&o(Wt));i!==Z;)r.push(i),Zt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=Z,0===hr&&o(Wt));r!==Z?(39===t.charCodeAt(ur)?(i=qt,ur++):(i=Z,0===hr&&o(Gt)),i!==Z?(cr=e,e=n=$t(r)):(ur=e,e=Z)):(ur=e,e=Z)}else ur=e,e=Z;return e}function F(){var e,n,r,i,s;return e=ur,n=C(),n!==Z?(r=ur,46===t.charCodeAt(ur)?(i=et,ur++):(i=Z,0===hr&&o(tt)),i!==Z?((s=C())===Z&&(s=null),s!==Z?r=i=[i,s]:(ur=r,r=Z)):(ur=r,r=Z),r===Z&&(r=null),r!==Z?(cr=e,e=n=Kt(n,r)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,46===t.charCodeAt(ur)?(n=et,ur++):(n=Z,0===hr&&o(tt)),n!==Z&&(r=C())!==Z?(cr=e,e=n=Qt(r)):(ur=e,e=Z)),e}function C(){var e,n,r;if(e=ur,n=[],en.test(t.charAt(ur))?(r=t.charAt(ur),ur++):(r=Z,0===hr&&o(tn)),r!==Z)for(;r!==Z;)n.push(r),en.test(t.charAt(ur))?(r=t.charAt(ur),ur++):(r=Z,0===hr&&o(tn));else n=Z;return n!==Z&&(cr=e,n=nn(n)),e=n}function M(){var e;return 42===t.charCodeAt(ur)?(e=rn,ur++):(e=Z,0===hr&&o(on)),e}function I(){var e,t;return e=ur,t=j(),t!==Z?(cr=ur,(sn(t)?void 0:Z)!==Z?(cr=e,e=t=an(t)):(ur=e,e=Z)):(ur=e,e=Z),e}function Y(){var e,n,r;return e=ur,36===t.charCodeAt(ur)?(n=un,ur++):(n=Z,0===hr&&o(cn)),n!==Z&&(r=j())!==Z?(cr=e,e=n=ln(r)):(ur=e,e=Z),e}function k(){var e,n,r,i;return e=ur,42===t.charCodeAt(ur)?(n=rn,ur++):(n=Z,0===hr&&o(on)),n!==Z&&(cr=e,n=pn()),(e=n)===Z&&(e=ur,(n=H())!==Z?(58===t.charCodeAt(ur)?(r=fn,ur++):(r=Z,0===hr&&o(hn)),r!==Z?(42===t.charCodeAt(ur)?(i=rn,ur++):(i=Z,0===hr&&o(on)),i!==Z?(cr=e,e=n=dn(n)):(ur=e,e=Z)):(ur=e,e=Z)):(ur=e,e=Z),e===Z&&(e=ur,(n=j())!==Z&&(cr=e,n=gn(n)),e=n)),e}function B(){var e;return t.substr(ur,7)===mn?(e=mn,ur+=7):(e=Z,0===hr&&o(vn)),e===Z&&(t.substr(ur,4)===wn?(e=wn,ur+=4):(e=Z,0===hr&&o(bn)),e===Z&&(t.substr(ur,22)===Ve?(e=Ve,ur+=22):(e=Z,0===hr&&o(Le)),e===Z&&(t.substr(ur,4)===yn?(e=yn,ur+=4):(e=Z,0===hr&&o(En))))),e}function X(){var e,n;if(e=[],Nn.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=Z,0===hr&&o(Dn)),n!==Z)for(;n!==Z;)e.push(n),Nn.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=Z,0===hr&&o(Dn));else e=Z;return e}function U(){var e;return(e=X())===Z&&(e=null),e}function j(){var e,t;return e=ur,(t=V())===Z&&(t=L()),t!==Z&&(cr=e,t=Tn(t)),e=t}function V(){var e,n,r,i;return e=ur,n=H(),n!==Z?(58===t.charCodeAt(ur)?(r=fn,ur++):(r=Z,0===hr&&o(hn)),r!==Z&&(i=H())!==Z?(cr=e,e=n=xn(n,i)):(ur=e,e=Z)):(ur=e,e=Z),e}function L(){var e,t;return e=ur,(t=H())!==Z&&(cr=e,t=Rn(t)),e=t}function H(){return $()}function J(){var e;return Sn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(An)),e===Z&&(95===t.charCodeAt(ur)?(e=_n,ur++):(e=Z,0===hr&&o(On)),e===Z&&(Pn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Fn)),e===Z&&(Cn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Mn)),e===Z&&(In.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Yn)),e===Z&&(kn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Bn)),e===Z&&(Xn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Un)),e===Z&&(jn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Vn)),e===Z&&(Ln.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Hn)),e===Z&&(Jn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(zn)),e===Z&&($n.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(qn)),e===Z&&(Gn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Zn)),e===Z&&(Wn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(Kn)),e===Z&&(Qn.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(er))))))))))))))),e}function z(){var e;return(e=J())===Z&&(45===t.charCodeAt(ur)?(e=Yt,ur++):(e=Z,0===hr&&o(kt)),e===Z&&(46===t.charCodeAt(ur)?(e=et,ur++):(e=Z,0===hr&&o(tt)),e===Z&&(en.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(tn)),e===Z&&(tr.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(nr)),e===Z&&(rr.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(or)),e===Z&&(ir.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=Z,0===hr&&o(sr)))))))),e}function $(){var e,t,n,r;if(e=ur,(t=J())!==Z){for(n=[],r=z();r!==Z;)n.push(r),r=z();n!==Z?(cr=e,e=t=ar(t,n)):(ur=e,e=Z)}else ur=e,e=Z;return e}var q,G=arguments.length>1?arguments[1]:{},Z={},W={XPath:s},K=s,Q=function(e){return{tree:e,nsPrefixes:vr}},ee="/",te={type:"literal",value:"/",description:'"/"'},ne=function(e){return{type:"/",args:[null,e?e[1]:null]}},re="//",oe={type:"literal",value:"//",description:'"//"'},ie=function(e,t){var n;for(n=0;n=",Pt={type:"literal",value:">=",description:'">="'},Ft=">",Ct={type:"literal",value:">",description:'">"'},Mt="+",It={type:"literal",value:"+",description:'"+"'},Yt="-",kt={type:"literal",value:"-",description:'"-"'},Bt="div",Xt={type:"literal",value:"div",description:'"div"'},Ut="mod",jt={type:"literal",value:"mod",description:'"mod"'},Vt=function(e){return{type:"*",args:[{type:"number",args:[-1]},e]}},Lt='"',Ht={type:"literal",value:'"',description:'"\\""'},Jt=/^[^"]/,zt={type:"class",value:'[^"]',description:'[^"]'},$t=function(e){return{type:"string",args:[e.join("")]}},qt="'",Gt={type:"literal",value:"'",description:'"\'"'},Zt=/^[^']/,Wt={type:"class",value:"[^']",description:"[^']"},Kt=function(e,t){return{type:"number",args:[t?parseFloat(e+"."+t[1]):parseInt(e)]}},Qt=function(e){return{type:"number",args:[parseFloat("."+e)]}},en=/^[0-9]/,tn={type:"class",value:"[0-9]",description:"[0-9]"},nn=function(e){return e.join("")},rn="*",on={type:"literal",value:"*",description:'"*"'},sn=function(e){var t;if(null===dr.args[0])for(t=0;t 0) { + count++; + } } - - return new NumberType(sum); + + return new NumberType(count); }, args: [ @@ -4038,7 +4037,6 @@ var XPathJS = (function(){ ret: 'number' }, - position: { /** * Hacked OpenRosa function to return the position of a nodeset argument diff --git a/test/doc.xml b/test/doc.xml index d093b7e..0c7f561 100644 --- a/test/doc.xml +++ b/test/doc.xml @@ -200,6 +200,21 @@
3
+ +
+
-5
+
-15
+
+

+

+
+ + + +

+

+
+ diff --git a/test/spec/functions-openrosa.spec.js b/test/spec/functions-openrosa.spec.js index e174b78..cd9d9fb 100644 --- a/test/spec/functions-openrosa.spec.js +++ b/test/spec/functions-openrosa.spec.js @@ -734,6 +734,36 @@ describe('Custom "OpenRosa" functions', function() { }); }); + it('count-non-empty', function() { + [ + ['count-non-empty(//xhtml:div[@id="FunctionCountNonEmpty"]/xhtml:div)', 2], + ['count-non-empty(//xhtml:div[@id="FunctionCountNonEmpty"]/xhtml:p)', 1], + ['count-non-empty(//xhtml:div[@id="FunctionCountNonEmpty"]/xhtml:p/xhtml:div)', 0], + ['count-non-empty(//xhtml:div[@id="FunctionCountNonEmpty"]/xhtml:p/xhtml:span)', 2], + ['count-non-empty(//xhtml:div[@id="FunctionCountNonEmpty"]//*)', 5], + ['count-non-empty(//xhtml:div[@id="NoExist"]/xhtml:div)', 0], + + ].forEach(function(t) { + var result = documentEvaluate(t[0], doc, helpers.xhtmlResolver, win.XPathResult.NUMBER_TYPE, null); + expect(result.numberValue).to.deep.equal(t[1]); + }); + }); + + it('count-non-empty fails when too few, too many, or incorrect arguments are provided', function() { + [ + 'count-non-empty()', + 'count-non-empty(2)', + 'count-non-empty(0)', + 'count-non-empty("a")', + ].forEach(function(t) { + var test = function(){ + documentEvaluate(t, doc, helpers.xhtmlResolver, win.XPathResult.NUMBER_TYPE, null); + }; + expect(test).to.throw(win.Error); + }); + + }); + /* This function is now supported by translating it into regular XPath before passing to this evaluator. it('indexed-repeat()', function() {