From cf4f2545cbaf1c6a42c71c03cf2628ffafbf6134 Mon Sep 17 00:00:00 2001
From: Slawomir Jaranowski
Date: Tue, 1 Oct 2019 23:09:18 +0200
Subject: [PATCH] node_modules with production
---
.gitignore | 2 +-
node_modules/@actions/core/README.md | 105 +
node_modules/@actions/core/lib/command.d.ts | 16 +
node_modules/@actions/core/lib/command.js | 66 +
node_modules/@actions/core/lib/command.js.map | 1 +
node_modules/@actions/core/lib/core.d.ts | 99 +
node_modules/@actions/core/lib/core.js | 176 +
node_modules/@actions/core/lib/core.js.map | 1 +
node_modules/@actions/core/package.json | 67 +
node_modules/xmldom/.npmignore | 5 +
node_modules/xmldom/.travis.yml | 22 +
node_modules/xmldom/LICENSE | 8 +
node_modules/xmldom/__package__.js | 4 +
node_modules/xmldom/changelog | 14 +
node_modules/xmldom/component.json | 10 +
node_modules/xmldom/dom-parser.js | 251 +
node_modules/xmldom/dom.js | 1244 +++++
node_modules/xmldom/package.json | 98 +
node_modules/xmldom/readme.md | 219 +
node_modules/xmldom/sax.js | 633 +++
node_modules/xpath/.npmignore | 1 +
node_modules/xpath/README.md | 133 +
node_modules/xpath/docs/XPathEvaluator.md | 62 +
node_modules/xpath/docs/XPathResult.md | 47 +
node_modules/xpath/docs/function resolvers.md | 88 +
.../xpath/docs/namespace resolvers.md | 69 +
node_modules/xpath/docs/parsed expressions.md | 21 +
node_modules/xpath/docs/variable resolvers.md | 89 +
node_modules/xpath/docs/xpath methods.md | 39 +
node_modules/xpath/package.json | 70 +
node_modules/xpath/test.js | 1092 ++++
node_modules/xpath/xpath.d.ts | 9 +
node_modules/xpath/xpath.js | 4764 +++++++++++++++++
33 files changed, 9524 insertions(+), 1 deletion(-)
create mode 100644 node_modules/@actions/core/README.md
create mode 100644 node_modules/@actions/core/lib/command.d.ts
create mode 100644 node_modules/@actions/core/lib/command.js
create mode 100644 node_modules/@actions/core/lib/command.js.map
create mode 100644 node_modules/@actions/core/lib/core.d.ts
create mode 100644 node_modules/@actions/core/lib/core.js
create mode 100644 node_modules/@actions/core/lib/core.js.map
create mode 100644 node_modules/@actions/core/package.json
create mode 100644 node_modules/xmldom/.npmignore
create mode 100644 node_modules/xmldom/.travis.yml
create mode 100644 node_modules/xmldom/LICENSE
create mode 100644 node_modules/xmldom/__package__.js
create mode 100644 node_modules/xmldom/changelog
create mode 100644 node_modules/xmldom/component.json
create mode 100644 node_modules/xmldom/dom-parser.js
create mode 100644 node_modules/xmldom/dom.js
create mode 100644 node_modules/xmldom/package.json
create mode 100644 node_modules/xmldom/readme.md
create mode 100644 node_modules/xmldom/sax.js
create mode 100644 node_modules/xpath/.npmignore
create mode 100644 node_modules/xpath/README.md
create mode 100644 node_modules/xpath/docs/XPathEvaluator.md
create mode 100644 node_modules/xpath/docs/XPathResult.md
create mode 100644 node_modules/xpath/docs/function resolvers.md
create mode 100644 node_modules/xpath/docs/namespace resolvers.md
create mode 100644 node_modules/xpath/docs/parsed expressions.md
create mode 100644 node_modules/xpath/docs/variable resolvers.md
create mode 100644 node_modules/xpath/docs/xpath methods.md
create mode 100644 node_modules/xpath/package.json
create mode 100644 node_modules/xpath/test.js
create mode 100644 node_modules/xpath/xpath.d.ts
create mode 100644 node_modules/xpath/xpath.js
diff --git a/.gitignore b/.gitignore
index 23c2fd1d..414c03d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
# comment this out distribution branches
-node_modules/
+# node_modules/
# Editors
.vscode
diff --git a/node_modules/@actions/core/README.md b/node_modules/@actions/core/README.md
new file mode 100644
index 00000000..860dce3d
--- /dev/null
+++ b/node_modules/@actions/core/README.md
@@ -0,0 +1,105 @@
+# `@actions/core`
+
+> Core functions for setting results, logging, registering secrets and exporting variables across actions
+
+## Usage
+
+### Import the package
+
+```js
+// javascript
+const core = require('@actions/core');
+
+// typescript
+import * as core from '@actions/core';
+```
+
+#### Inputs/Outputs
+
+Action inputs can be read with `getInput`. Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
+
+```js
+const myInput = core.getInput('inputName', { required: true });
+
+core.setOutput('outputKey', 'outputVal');
+```
+
+#### Exporting variables
+
+Since each step runs in a separate process, you can use `exportVariable` to add it to this step and future steps environment blocks.
+
+```js
+core.exportVariable('envVar', 'Val');
+```
+
+Exporting a secret exports the variable but also registers the secret with the runner to ensure it is masked in logs.
+
+```js
+core.exportSecret('myPassword', mypass);
+```
+
+#### PATH Manipulation
+
+To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `addPath`. The runner will prepend the path given to the jobs PATH.
+
+```js
+core.addPath('/path/to/mytool');
+```
+
+#### Exit codes
+
+You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
+
+```js
+const core = require('@actions/core');
+
+try {
+ // Do stuff
+}
+catch (err) {
+ // setFailed logs the message and sets a failing exit code
+ core.setFailed(`Action failed with error ${err}`);
+}
+
+Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
+
+```
+
+#### Logging
+
+Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
+
+```js
+const core = require('@actions/core');
+
+const myInput = core.getInput('input');
+try {
+ core.debug('Inside try block');
+
+ if (!myInput) {
+ core.warning('myInput was not set');
+ }
+
+ // Do stuff
+}
+catch (err) {
+ core.error(`Error ${err}, action may still succeed though`);
+}
+```
+
+This library can also wrap chunks of output in foldable groups.
+
+```js
+const core = require('@actions/core')
+
+// Manually wrap output
+core.startGroup('Do some function')
+doSomeFunction()
+core.endGroup()
+
+// Wrap an asynchronous function call
+const result = await core.group('Do something async', async () => {
+ const response = await doSomeHTTPRequest()
+ return response
+})
+```
\ No newline at end of file
diff --git a/node_modules/@actions/core/lib/command.d.ts b/node_modules/@actions/core/lib/command.d.ts
new file mode 100644
index 00000000..7f6fecbe
--- /dev/null
+++ b/node_modules/@actions/core/lib/command.d.ts
@@ -0,0 +1,16 @@
+interface CommandProperties {
+ [key: string]: string;
+}
+/**
+ * Commands
+ *
+ * Command Format:
+ * ##[name key=value;key=value]message
+ *
+ * Examples:
+ * ##[warning]This is the user warning message
+ * ##[set-secret name=mypassword]definitelyNotAPassword!
+ */
+export declare function issueCommand(command: string, properties: CommandProperties, message: string): void;
+export declare function issue(name: string, message?: string): void;
+export {};
diff --git a/node_modules/@actions/core/lib/command.js b/node_modules/@actions/core/lib/command.js
new file mode 100644
index 00000000..b0ea009a
--- /dev/null
+++ b/node_modules/@actions/core/lib/command.js
@@ -0,0 +1,66 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const os = require("os");
+/**
+ * Commands
+ *
+ * Command Format:
+ * ##[name key=value;key=value]message
+ *
+ * Examples:
+ * ##[warning]This is the user warning message
+ * ##[set-secret name=mypassword]definitelyNotAPassword!
+ */
+function issueCommand(command, properties, message) {
+ const cmd = new Command(command, properties, message);
+ process.stdout.write(cmd.toString() + os.EOL);
+}
+exports.issueCommand = issueCommand;
+function issue(name, message = '') {
+ issueCommand(name, {}, message);
+}
+exports.issue = issue;
+const CMD_STRING = '::';
+class Command {
+ constructor(command, properties, message) {
+ if (!command) {
+ command = 'missing.command';
+ }
+ this.command = command;
+ this.properties = properties;
+ this.message = message;
+ }
+ toString() {
+ let cmdStr = CMD_STRING + this.command;
+ if (this.properties && Object.keys(this.properties).length > 0) {
+ cmdStr += ' ';
+ for (const key in this.properties) {
+ if (this.properties.hasOwnProperty(key)) {
+ const val = this.properties[key];
+ if (val) {
+ // safely append the val - avoid blowing up when attempting to
+ // call .replace() if message is not a string for some reason
+ cmdStr += `${key}=${escape(`${val || ''}`)},`;
+ }
+ }
+ }
+ }
+ cmdStr += CMD_STRING;
+ // safely append the message - avoid blowing up when attempting to
+ // call .replace() if message is not a string for some reason
+ const message = `${this.message || ''}`;
+ cmdStr += escapeData(message);
+ return cmdStr;
+ }
+}
+function escapeData(s) {
+ return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A');
+}
+function escape(s) {
+ return s
+ .replace(/\r/g, '%0D')
+ .replace(/\n/g, '%0A')
+ .replace(/]/g, '%5D')
+ .replace(/;/g, '%3B');
+}
+//# sourceMappingURL=command.js.map
\ No newline at end of file
diff --git a/node_modules/@actions/core/lib/command.js.map b/node_modules/@actions/core/lib/command.js.map
new file mode 100644
index 00000000..918ab25b
--- /dev/null
+++ b/node_modules/@actions/core/lib/command.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;AAAA,yBAAwB;AAQxB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,UAA6B,EAC7B,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC;AAPD,oCAOC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,UAAkB,EAAE;IACtD,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC;AAED,MAAM,UAAU,GAAG,IAAI,CAAA;AAEvB,MAAM,OAAO;IAKX,YAAY,OAAe,EAAE,UAA6B,EAAE,OAAe;QACzE,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,iBAAiB,CAAA;SAC5B;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,QAAQ;QACN,IAAI,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,CAAA;QAEtC,IAAI,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9D,MAAM,IAAI,GAAG,CAAA;YACb,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjC,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;oBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;oBAChC,IAAI,GAAG,EAAE;wBACP,8DAA8D;wBAC9D,6DAA6D;wBAC7D,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAA;qBAC9C;iBACF;aACF;SACF;QAED,MAAM,IAAI,UAAU,CAAA;QAEpB,kEAAkE;QAClE,6DAA6D;QAC7D,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,CAAA;QACvC,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;QAE7B,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AACtD,CAAC;AAED,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO,CAAC;SACL,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}
\ No newline at end of file
diff --git a/node_modules/@actions/core/lib/core.d.ts b/node_modules/@actions/core/lib/core.d.ts
new file mode 100644
index 00000000..116b0480
--- /dev/null
+++ b/node_modules/@actions/core/lib/core.d.ts
@@ -0,0 +1,99 @@
+/**
+ * Interface for getInput options
+ */
+export interface InputOptions {
+ /** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
+ required?: boolean;
+}
+/**
+ * The code to exit an action
+ */
+export declare enum ExitCode {
+ /**
+ * A code indicating that the action was successful
+ */
+ Success = 0,
+ /**
+ * A code indicating that the action was a failure
+ */
+ Failure = 1
+}
+/**
+ * sets env variable for this action and future actions in the job
+ * @param name the name of the variable to set
+ * @param val the value of the variable
+ */
+export declare function exportVariable(name: string, val: string): void;
+/**
+ * exports the variable and registers a secret which will get masked from logs
+ * @param name the name of the variable to set
+ * @param val value of the secret
+ */
+export declare function exportSecret(name: string, val: string): void;
+/**
+ * Prepends inputPath to the PATH (for this action and future actions)
+ * @param inputPath
+ */
+export declare function addPath(inputPath: string): void;
+/**
+ * Gets the value of an input. The value is also trimmed.
+ *
+ * @param name name of the input to get
+ * @param options optional. See InputOptions.
+ * @returns string
+ */
+export declare function getInput(name: string, options?: InputOptions): string;
+/**
+ * Sets the value of an output.
+ *
+ * @param name name of the output to set
+ * @param value value to store
+ */
+export declare function setOutput(name: string, value: string): void;
+/**
+ * Sets the action status to failed.
+ * When the action exits it will be with an exit code of 1
+ * @param message add error issue message
+ */
+export declare function setFailed(message: string): void;
+/**
+ * Writes debug message to user log
+ * @param message debug message
+ */
+export declare function debug(message: string): void;
+/**
+ * Adds an error issue
+ * @param message error issue message
+ */
+export declare function error(message: string): void;
+/**
+ * Adds an warning issue
+ * @param message warning issue message
+ */
+export declare function warning(message: string): void;
+/**
+ * Writes info to log with console.log.
+ * @param message info message
+ */
+export declare function info(message: string): void;
+/**
+ * Begin an output group.
+ *
+ * Output until the next `groupEnd` will be foldable in this group
+ *
+ * @param name The name of the output group
+ */
+export declare function startGroup(name: string): void;
+/**
+ * End an output group.
+ */
+export declare function endGroup(): void;
+/**
+ * Wrap an asynchronous function call in a group.
+ *
+ * Returns the same type as the function itself.
+ *
+ * @param name The name of the group
+ * @param fn The function to wrap in the group
+ */
+export declare function group(name: string, fn: () => Promise): Promise;
diff --git a/node_modules/@actions/core/lib/core.js b/node_modules/@actions/core/lib/core.js
new file mode 100644
index 00000000..2597940c
--- /dev/null
+++ b/node_modules/@actions/core/lib/core.js
@@ -0,0 +1,176 @@
+"use strict";
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const command_1 = require("./command");
+const os = require("os");
+const path = require("path");
+/**
+ * The code to exit an action
+ */
+var ExitCode;
+(function (ExitCode) {
+ /**
+ * A code indicating that the action was successful
+ */
+ ExitCode[ExitCode["Success"] = 0] = "Success";
+ /**
+ * A code indicating that the action was a failure
+ */
+ ExitCode[ExitCode["Failure"] = 1] = "Failure";
+})(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
+//-----------------------------------------------------------------------
+// Variables
+//-----------------------------------------------------------------------
+/**
+ * sets env variable for this action and future actions in the job
+ * @param name the name of the variable to set
+ * @param val the value of the variable
+ */
+function exportVariable(name, val) {
+ process.env[name] = val;
+ command_1.issueCommand('set-env', { name }, val);
+}
+exports.exportVariable = exportVariable;
+/**
+ * exports the variable and registers a secret which will get masked from logs
+ * @param name the name of the variable to set
+ * @param val value of the secret
+ */
+function exportSecret(name, val) {
+ exportVariable(name, val);
+ // the runner will error with not implemented
+ // leaving the function but raising the error earlier
+ command_1.issueCommand('set-secret', {}, val);
+}
+exports.exportSecret = exportSecret;
+/**
+ * Prepends inputPath to the PATH (for this action and future actions)
+ * @param inputPath
+ */
+function addPath(inputPath) {
+ command_1.issueCommand('add-path', {}, inputPath);
+ process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
+}
+exports.addPath = addPath;
+/**
+ * Gets the value of an input. The value is also trimmed.
+ *
+ * @param name name of the input to get
+ * @param options optional. See InputOptions.
+ * @returns string
+ */
+function getInput(name, options) {
+ const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
+ if (options && options.required && !val) {
+ throw new Error(`Input required and not supplied: ${name}`);
+ }
+ return val.trim();
+}
+exports.getInput = getInput;
+/**
+ * Sets the value of an output.
+ *
+ * @param name name of the output to set
+ * @param value value to store
+ */
+function setOutput(name, value) {
+ command_1.issueCommand('set-output', { name }, value);
+}
+exports.setOutput = setOutput;
+//-----------------------------------------------------------------------
+// Results
+//-----------------------------------------------------------------------
+/**
+ * Sets the action status to failed.
+ * When the action exits it will be with an exit code of 1
+ * @param message add error issue message
+ */
+function setFailed(message) {
+ process.exitCode = ExitCode.Failure;
+ error(message);
+}
+exports.setFailed = setFailed;
+//-----------------------------------------------------------------------
+// Logging Commands
+//-----------------------------------------------------------------------
+/**
+ * Writes debug message to user log
+ * @param message debug message
+ */
+function debug(message) {
+ command_1.issueCommand('debug', {}, message);
+}
+exports.debug = debug;
+/**
+ * Adds an error issue
+ * @param message error issue message
+ */
+function error(message) {
+ command_1.issue('error', message);
+}
+exports.error = error;
+/**
+ * Adds an warning issue
+ * @param message warning issue message
+ */
+function warning(message) {
+ command_1.issue('warning', message);
+}
+exports.warning = warning;
+/**
+ * Writes info to log with console.log.
+ * @param message info message
+ */
+function info(message) {
+ process.stdout.write(message + os.EOL);
+}
+exports.info = info;
+/**
+ * Begin an output group.
+ *
+ * Output until the next `groupEnd` will be foldable in this group
+ *
+ * @param name The name of the output group
+ */
+function startGroup(name) {
+ command_1.issue('group', name);
+}
+exports.startGroup = startGroup;
+/**
+ * End an output group.
+ */
+function endGroup() {
+ command_1.issue('endgroup');
+}
+exports.endGroup = endGroup;
+/**
+ * Wrap an asynchronous function call in a group.
+ *
+ * Returns the same type as the function itself.
+ *
+ * @param name The name of the group
+ * @param fn The function to wrap in the group
+ */
+function group(name, fn) {
+ return __awaiter(this, void 0, void 0, function* () {
+ startGroup(name);
+ let result;
+ try {
+ result = yield fn();
+ }
+ finally {
+ endGroup();
+ }
+ return result;
+ });
+}
+exports.group = group;
+//# sourceMappingURL=core.js.map
\ No newline at end of file
diff --git a/node_modules/@actions/core/lib/core.js.map b/node_modules/@actions/core/lib/core.js.map
new file mode 100644
index 00000000..790eb7bd
--- /dev/null
+++ b/node_modules/@actions/core/lib/core.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAA6C;AAE7C,yBAAwB;AACxB,6BAA4B;AAU5B;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB;;OAEG;IACH,6CAAW,CAAA;IAEX;;OAEG;IACH,6CAAW,CAAA;AACb,CAAC,EAVW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAUnB;AAED,yEAAyE;AACzE,YAAY;AACZ,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,GAAW;IACtD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;IACvB,sBAAY,CAAC,SAAS,EAAE,EAAC,IAAI,EAAC,EAAE,GAAG,CAAC,CAAA;AACtC,CAAC;AAHD,wCAGC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,GAAW;IACpD,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAEzB,6CAA6C;IAC7C,qDAAqD;IACrD,sBAAY,CAAC,YAAY,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;AACrC,CAAC;AAND,oCAMC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,sBAAY,CAAC,UAAU,EAAE,EAAE,EAAE,SAAS,CAAC,CAAA;IACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,SAAS,GAAG,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;AAC7E,CAAC;AAHD,0BAGC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAY,EAAE,OAAsB;IAC3D,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IACrE,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAA;KAC5D;IAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AARD,4BAQC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,sBAAY,CAAC,YAAY,EAAE,EAAC,IAAI,EAAC,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAFD,8BAEC;AAED,yEAAyE;AACzE,UAAU;AACV,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,SAAS,CAAC,OAAe;IACvC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAA;IACnC,KAAK,CAAC,OAAO,CAAC,CAAA;AAChB,CAAC;AAHD,8BAGC;AAED,yEAAyE;AACzE,mBAAmB;AACnB,yEAAyE;AAEzE;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,sBAAY,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,eAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,OAAe;IACrC,eAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AAC3B,CAAC;AAFD,0BAEC;AAED;;;GAGG;AACH,SAAgB,IAAI,CAAC,OAAe;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AACxC,CAAC;AAFD,oBAEC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,eAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACtB,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,QAAQ;IACtB,eAAK,CAAC,UAAU,CAAC,CAAA;AACnB,CAAC;AAFD,4BAEC;AAED;;;;;;;GAOG;AACH,SAAsB,KAAK,CAAI,IAAY,EAAE,EAAoB;;QAC/D,UAAU,CAAC,IAAI,CAAC,CAAA;QAEhB,IAAI,MAAS,CAAA;QAEb,IAAI;YACF,MAAM,GAAG,MAAM,EAAE,EAAE,CAAA;SACpB;gBAAS;YACR,QAAQ,EAAE,CAAA;SACX;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CAAA;AAZD,sBAYC"}
\ No newline at end of file
diff --git a/node_modules/@actions/core/package.json b/node_modules/@actions/core/package.json
new file mode 100644
index 00000000..a42e4f02
--- /dev/null
+++ b/node_modules/@actions/core/package.json
@@ -0,0 +1,67 @@
+{
+ "_args": [
+ [
+ "@actions/core@1.1.2",
+ "/Users/slawomir.jaranowski/dev/x_my/s4u/maven-settings-action"
+ ]
+ ],
+ "_from": "@actions/core@1.1.2",
+ "_id": "@actions/core@1.1.2",
+ "_inBundle": false,
+ "_integrity": "sha512-l8Ol2wEzFeuhV1v7LbGB2x8ghXSnmUiSVKVSjsNwgqAU4i5LvGRXpM+kli9gNMkGVudwZYHET4qZ5DTep5Sssw==",
+ "_location": "/@actions/core",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "version",
+ "registry": true,
+ "raw": "@actions/core@1.1.2",
+ "name": "@actions/core",
+ "escapedName": "@actions%2fcore",
+ "scope": "@actions",
+ "rawSpec": "1.1.2",
+ "saveSpec": null,
+ "fetchSpec": "1.1.2"
+ },
+ "_requiredBy": [
+ "/"
+ ],
+ "_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.2.tgz",
+ "_spec": "1.1.2",
+ "_where": "/Users/slawomir.jaranowski/dev/x_my/s4u/maven-settings-action",
+ "bugs": {
+ "url": "https://github.com/actions/toolkit/issues"
+ },
+ "description": "Actions core lib",
+ "devDependencies": {
+ "@types/node": "^12.0.2"
+ },
+ "directories": {
+ "lib": "lib",
+ "test": "__tests__"
+ },
+ "files": [
+ "lib"
+ ],
+ "homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
+ "keywords": [
+ "github",
+ "actions",
+ "core"
+ ],
+ "license": "MIT",
+ "main": "lib/core.js",
+ "name": "@actions/core",
+ "publishConfig": {
+ "access": "public"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/actions/toolkit.git",
+ "directory": "packages/core"
+ },
+ "scripts": {
+ "test": "echo \"Error: run tests from root\" && exit 1",
+ "tsc": "tsc"
+ },
+ "version": "1.1.2"
+}
diff --git a/node_modules/xmldom/.npmignore b/node_modules/xmldom/.npmignore
new file mode 100644
index 00000000..b094a442
--- /dev/null
+++ b/node_modules/xmldom/.npmignore
@@ -0,0 +1,5 @@
+test
+t
+travis.yml
+.project
+changelog
diff --git a/node_modules/xmldom/.travis.yml b/node_modules/xmldom/.travis.yml
new file mode 100644
index 00000000..b95408e8
--- /dev/null
+++ b/node_modules/xmldom/.travis.yml
@@ -0,0 +1,22 @@
+language: node_js
+
+node_js:
+ - '0.10'
+
+branches:
+ only:
+ - master
+ - proof
+ - travis-ci
+
+# Not using `npm install --dev` because it is recursive. It will pull in the all
+# development dependencies for CoffeeScript. Way too much spew in the Travis CI
+# build output.
+
+before_install:
+ - npm install
+ - npm install istanbul coveralls
+
+env:
+ global:
+ - secure: "BxUHTsa1WVANLQoimilbZwa1MCWSdM9hOmPWBE/rsYb7uT/iiqkRXXwnWhKtN5CLvTvIQbiAzq4iyPID0S8UHrnxClYQrOuA6QkrtwgIEuDAmijao/bgxobPOremvkwXcpMGIwzYKyYQQtSEaEIQbqf6gSSKW9dBh/GZ/vfTsqo="
diff --git a/node_modules/xmldom/LICENSE b/node_modules/xmldom/LICENSE
new file mode 100644
index 00000000..68a9b5e1
--- /dev/null
+++ b/node_modules/xmldom/LICENSE
@@ -0,0 +1,8 @@
+You can choose any one of those:
+
+The MIT License (MIT):
+
+link:http://opensource.org/licenses/MIT
+
+LGPL:
+http://www.gnu.org/licenses/lgpl.html
diff --git a/node_modules/xmldom/__package__.js b/node_modules/xmldom/__package__.js
new file mode 100644
index 00000000..b4cad289
--- /dev/null
+++ b/node_modules/xmldom/__package__.js
@@ -0,0 +1,4 @@
+this.addScript('dom.js',['DOMImplementation','XMLSerializer']);
+this.addScript('dom-parser.js',['DOMHandler','DOMParser'],
+ ['DOMImplementation','XMLReader']);
+this.addScript('sax.js','XMLReader');
\ No newline at end of file
diff --git a/node_modules/xmldom/changelog b/node_modules/xmldom/changelog
new file mode 100644
index 00000000..ab815bb8
--- /dev/null
+++ b/node_modules/xmldom/changelog
@@ -0,0 +1,14 @@
+### Version 0.1.16
+
+Sat May 4 14:58:03 UTC 2013
+
+ * Correctly handle multibyte Unicode greater than two byts. #57. #56.
+ * Initial unit testing and test coverage. #53. #46. #19.
+ * Create Bower `component.json` #52.
+
+### Version 0.1.8
+
+ * Add: some test case from node-o3-xml(excludes xpath support)
+ * Fix: remove existed attribute before setting (bug introduced in v0.1.5)
+ * Fix: index direct access for childNodes and any NodeList collection(not w3c standard)
+ * Fix: remove last child bug
diff --git a/node_modules/xmldom/component.json b/node_modules/xmldom/component.json
new file mode 100644
index 00000000..93b4d570
--- /dev/null
+++ b/node_modules/xmldom/component.json
@@ -0,0 +1,10 @@
+{
+ "name": "xmldom",
+ "version": "0.1.15",
+ "main": "dom-parser.js",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "components"
+ ]
+}
diff --git a/node_modules/xmldom/dom-parser.js b/node_modules/xmldom/dom-parser.js
new file mode 100644
index 00000000..41d52267
--- /dev/null
+++ b/node_modules/xmldom/dom-parser.js
@@ -0,0 +1,251 @@
+function DOMParser(options){
+ this.options = options ||{locator:{}};
+
+}
+DOMParser.prototype.parseFromString = function(source,mimeType){
+ var options = this.options;
+ var sax = new XMLReader();
+ var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
+ var errorHandler = options.errorHandler;
+ var locator = options.locator;
+ var defaultNSMap = options.xmlns||{};
+ var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
+ if(locator){
+ domBuilder.setDocumentLocator(locator)
+ }
+
+ sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
+ sax.domBuilder = options.domBuilder || domBuilder;
+ if(/\/x?html?$/.test(mimeType)){
+ entityMap.nbsp = '\xa0';
+ entityMap.copy = '\xa9';
+ defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
+ }
+ defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
+ if(source){
+ sax.parse(source,defaultNSMap,entityMap);
+ }else{
+ sax.errorHandler.error("invalid doc source");
+ }
+ return domBuilder.doc;
+}
+function buildErrorHandler(errorImpl,domBuilder,locator){
+ if(!errorImpl){
+ if(domBuilder instanceof DOMHandler){
+ return domBuilder;
+ }
+ errorImpl = domBuilder ;
+ }
+ var errorHandler = {}
+ var isCallback = errorImpl instanceof Function;
+ locator = locator||{}
+ function build(key){
+ var fn = errorImpl[key];
+ if(!fn && isCallback){
+ fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
+ }
+ errorHandler[key] = fn && function(msg){
+ fn('[xmldom '+key+']\t'+msg+_locator(locator));
+ }||function(){};
+ }
+ build('warning');
+ build('error');
+ build('fatalError');
+ return errorHandler;
+}
+
+//console.log('#\n\n\n\n\n\n\n####')
+/**
+ * +ContentHandler+ErrorHandler
+ * +LexicalHandler+EntityResolver2
+ * -DeclHandler-DTDHandler
+ *
+ * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
+ * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
+ */
+function DOMHandler() {
+ this.cdata = false;
+}
+function position(locator,node){
+ node.lineNumber = locator.lineNumber;
+ node.columnNumber = locator.columnNumber;
+}
+/**
+ * @see org.xml.sax.ContentHandler#startDocument
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
+ */
+DOMHandler.prototype = {
+ startDocument : function() {
+ this.doc = new DOMImplementation().createDocument(null, null, null);
+ if (this.locator) {
+ this.doc.documentURI = this.locator.systemId;
+ }
+ },
+ startElement:function(namespaceURI, localName, qName, attrs) {
+ var doc = this.doc;
+ var el = doc.createElementNS(namespaceURI, qName||localName);
+ var len = attrs.length;
+ appendElement(this, el);
+ this.currentElement = el;
+
+ this.locator && position(this.locator,el)
+ for (var i = 0 ; i < len; i++) {
+ var namespaceURI = attrs.getURI(i);
+ var value = attrs.getValue(i);
+ var qName = attrs.getQName(i);
+ var attr = doc.createAttributeNS(namespaceURI, qName);
+ this.locator &&position(attrs.getLocator(i),attr);
+ attr.value = attr.nodeValue = value;
+ el.setAttributeNode(attr)
+ }
+ },
+ endElement:function(namespaceURI, localName, qName) {
+ var current = this.currentElement
+ var tagName = current.tagName;
+ this.currentElement = current.parentNode;
+ },
+ startPrefixMapping:function(prefix, uri) {
+ },
+ endPrefixMapping:function(prefix) {
+ },
+ processingInstruction:function(target, data) {
+ var ins = this.doc.createProcessingInstruction(target, data);
+ this.locator && position(this.locator,ins)
+ appendElement(this, ins);
+ },
+ ignorableWhitespace:function(ch, start, length) {
+ },
+ characters:function(chars, start, length) {
+ chars = _toString.apply(this,arguments)
+ //console.log(chars)
+ if(chars){
+ if (this.cdata) {
+ var charNode = this.doc.createCDATASection(chars);
+ } else {
+ var charNode = this.doc.createTextNode(chars);
+ }
+ if(this.currentElement){
+ this.currentElement.appendChild(charNode);
+ }else if(/^\s*$/.test(chars)){
+ this.doc.appendChild(charNode);
+ //process xml
+ }
+ this.locator && position(this.locator,charNode)
+ }
+ },
+ skippedEntity:function(name) {
+ },
+ endDocument:function() {
+ this.doc.normalize();
+ },
+ setDocumentLocator:function (locator) {
+ if(this.locator = locator){// && !('lineNumber' in locator)){
+ locator.lineNumber = 0;
+ }
+ },
+ //LexicalHandler
+ comment:function(chars, start, length) {
+ chars = _toString.apply(this,arguments)
+ var comm = this.doc.createComment(chars);
+ this.locator && position(this.locator,comm)
+ appendElement(this, comm);
+ },
+
+ startCDATA:function() {
+ //used in characters() methods
+ this.cdata = true;
+ },
+ endCDATA:function() {
+ this.cdata = false;
+ },
+
+ startDTD:function(name, publicId, systemId) {
+ var impl = this.doc.implementation;
+ if (impl && impl.createDocumentType) {
+ var dt = impl.createDocumentType(name, publicId, systemId);
+ this.locator && position(this.locator,dt)
+ appendElement(this, dt);
+ }
+ },
+ /**
+ * @see org.xml.sax.ErrorHandler
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
+ */
+ warning:function(error) {
+ console.warn('[xmldom warning]\t'+error,_locator(this.locator));
+ },
+ error:function(error) {
+ console.error('[xmldom error]\t'+error,_locator(this.locator));
+ },
+ fatalError:function(error) {
+ console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
+ throw error;
+ }
+}
+function _locator(l){
+ if(l){
+ return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
+ }
+}
+function _toString(chars,start,length){
+ if(typeof chars == 'string'){
+ return chars.substr(start,length)
+ }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
+ if(chars.length >= start+length || start){
+ return new java.lang.String(chars,start,length)+'';
+ }
+ return chars;
+ }
+}
+
+/*
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
+ * used method of org.xml.sax.ext.LexicalHandler:
+ * #comment(chars, start, length)
+ * #startCDATA()
+ * #endCDATA()
+ * #startDTD(name, publicId, systemId)
+ *
+ *
+ * IGNORED method of org.xml.sax.ext.LexicalHandler:
+ * #endDTD()
+ * #startEntity(name)
+ * #endEntity(name)
+ *
+ *
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
+ * IGNORED method of org.xml.sax.ext.DeclHandler
+ * #attributeDecl(eName, aName, type, mode, value)
+ * #elementDecl(name, model)
+ * #externalEntityDecl(name, publicId, systemId)
+ * #internalEntityDecl(name, value)
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
+ * IGNORED method of org.xml.sax.EntityResolver2
+ * #resolveEntity(String name,String publicId,String baseURI,String systemId)
+ * #resolveEntity(publicId, systemId)
+ * #getExternalSubset(name, baseURI)
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
+ * IGNORED method of org.xml.sax.DTDHandler
+ * #notationDecl(name, publicId, systemId) {};
+ * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
+ */
+"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
+ DOMHandler.prototype[key] = function(){return null}
+})
+
+/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
+function appendElement (hander,node) {
+ if (!hander.currentElement) {
+ hander.doc.appendChild(node);
+ } else {
+ hander.currentElement.appendChild(node);
+ }
+}//appendChild and setAttributeNS are preformance key
+
+//if(typeof require == 'function'){
+ var XMLReader = require('./sax').XMLReader;
+ var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
+ exports.XMLSerializer = require('./dom').XMLSerializer ;
+ exports.DOMParser = DOMParser;
+//}
diff --git a/node_modules/xmldom/dom.js b/node_modules/xmldom/dom.js
new file mode 100644
index 00000000..b290df08
--- /dev/null
+++ b/node_modules/xmldom/dom.js
@@ -0,0 +1,1244 @@
+/*
+ * DOM Level 2
+ * Object DOMException
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
+ */
+
+function copy(src,dest){
+ for(var p in src){
+ dest[p] = src[p];
+ }
+}
+/**
+^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
+^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
+ */
+function _extends(Class,Super){
+ var pt = Class.prototype;
+ if(Object.create){
+ var ppt = Object.create(Super.prototype)
+ pt.__proto__ = ppt;
+ }
+ if(!(pt instanceof Super)){
+ function t(){};
+ t.prototype = Super.prototype;
+ t = new t();
+ copy(pt,t);
+ Class.prototype = pt = t;
+ }
+ if(pt.constructor != Class){
+ if(typeof Class != 'function'){
+ console.error("unknow Class:"+Class)
+ }
+ pt.constructor = Class
+ }
+}
+var htmlns = 'http://www.w3.org/1999/xhtml' ;
+// Node Types
+var NodeType = {}
+var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
+var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
+var TEXT_NODE = NodeType.TEXT_NODE = 3;
+var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
+var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
+var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
+var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
+var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
+var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
+var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
+var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
+var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
+
+// ExceptionCode
+var ExceptionCode = {}
+var ExceptionMessage = {};
+var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
+var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
+var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
+var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
+var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
+var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
+var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
+var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
+var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
+var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
+//level2
+var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
+var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
+var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
+var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
+var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
+
+
+function DOMException(code, message) {
+ if(message instanceof Error){
+ var error = message;
+ }else{
+ error = this;
+ Error.call(this, ExceptionMessage[code]);
+ this.message = ExceptionMessage[code];
+ if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
+ }
+ error.code = code;
+ if(message) this.message = this.message + ": " + message;
+ return error;
+};
+DOMException.prototype = Error.prototype;
+copy(ExceptionCode,DOMException)
+/**
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
+ * The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live.
+ * The items in the NodeList are accessible via an integral index, starting from 0.
+ */
+function NodeList() {
+};
+NodeList.prototype = {
+ /**
+ * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
+ * @standard level1
+ */
+ length:0,
+ /**
+ * Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
+ * @standard level1
+ * @param index unsigned long
+ * Index into the collection.
+ * @return Node
+ * The node at the indexth position in the NodeList, or null if that is not a valid index.
+ */
+ item: function(index) {
+ return this[index] || null;
+ },
+ toString:function(isHTML,nodeFilter){
+ for(var buf = [], i = 0;i=0){
+ var lastIndex = list.length-1
+ while(i0 || key == 'xmlns'){
+// return null;
+// }
+ //console.log()
+ var i = this.length;
+ while(i--){
+ var attr = this[i];
+ //console.log(attr.nodeName,key)
+ if(attr.nodeName == key){
+ return attr;
+ }
+ }
+ },
+ setNamedItem: function(attr) {
+ var el = attr.ownerElement;
+ if(el && el!=this._ownerElement){
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
+ }
+ var oldAttr = this.getNamedItem(attr.nodeName);
+ _addNamedNode(this._ownerElement,this,attr,oldAttr);
+ return oldAttr;
+ },
+ /* returns Node */
+ setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
+ var el = attr.ownerElement, oldAttr;
+ if(el && el!=this._ownerElement){
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
+ }
+ oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
+ _addNamedNode(this._ownerElement,this,attr,oldAttr);
+ return oldAttr;
+ },
+
+ /* returns Node */
+ removeNamedItem: function(key) {
+ var attr = this.getNamedItem(key);
+ _removeNamedNode(this._ownerElement,this,attr);
+ return attr;
+
+
+ },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
+
+ //for level2
+ removeNamedItemNS:function(namespaceURI,localName){
+ var attr = this.getNamedItemNS(namespaceURI,localName);
+ _removeNamedNode(this._ownerElement,this,attr);
+ return attr;
+ },
+ getNamedItemNS: function(namespaceURI, localName) {
+ var i = this.length;
+ while(i--){
+ var node = this[i];
+ if(node.localName == localName && node.namespaceURI == namespaceURI){
+ return node;
+ }
+ }
+ return null;
+ }
+};
+/**
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
+ */
+function DOMImplementation(/* Object */ features) {
+ this._features = {};
+ if (features) {
+ for (var feature in features) {
+ this._features = features[feature];
+ }
+ }
+};
+
+DOMImplementation.prototype = {
+ hasFeature: function(/* string */ feature, /* string */ version) {
+ var versions = this._features[feature.toLowerCase()];
+ if (versions && (!version || version in versions)) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+ // Introduced in DOM Level 2:
+ createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
+ var doc = new Document();
+ doc.implementation = this;
+ doc.childNodes = new NodeList();
+ doc.doctype = doctype;
+ if(doctype){
+ doc.appendChild(doctype);
+ }
+ if(qualifiedName){
+ var root = doc.createElementNS(namespaceURI,qualifiedName);
+ doc.appendChild(root);
+ }
+ return doc;
+ },
+ // Introduced in DOM Level 2:
+ createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
+ var node = new DocumentType();
+ node.name = qualifiedName;
+ node.nodeName = qualifiedName;
+ node.publicId = publicId;
+ node.systemId = systemId;
+ // Introduced in DOM Level 2:
+ //readonly attribute DOMString internalSubset;
+
+ //TODO:..
+ // readonly attribute NamedNodeMap entities;
+ // readonly attribute NamedNodeMap notations;
+ return node;
+ }
+};
+
+
+/**
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247
+ */
+
+function Node() {
+};
+
+Node.prototype = {
+ firstChild : null,
+ lastChild : null,
+ previousSibling : null,
+ nextSibling : null,
+ attributes : null,
+ parentNode : null,
+ childNodes : null,
+ ownerDocument : null,
+ nodeValue : null,
+ namespaceURI : null,
+ prefix : null,
+ localName : null,
+ // Modified in DOM Level 2:
+ insertBefore:function(newChild, refChild){//raises
+ return _insertBefore(this,newChild,refChild);
+ },
+ replaceChild:function(newChild, oldChild){//raises
+ this.insertBefore(newChild,oldChild);
+ if(oldChild){
+ this.removeChild(oldChild);
+ }
+ },
+ removeChild:function(oldChild){
+ return _removeChild(this,oldChild);
+ },
+ appendChild:function(newChild){
+ return this.insertBefore(newChild,null);
+ },
+ hasChildNodes:function(){
+ return this.firstChild != null;
+ },
+ cloneNode:function(deep){
+ return cloneNode(this.ownerDocument||this,this,deep);
+ },
+ // Modified in DOM Level 2:
+ normalize:function(){
+ var child = this.firstChild;
+ while(child){
+ var next = child.nextSibling;
+ if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
+ this.removeChild(next);
+ child.appendData(next.data);
+ }else{
+ child.normalize();
+ child = next;
+ }
+ }
+ },
+ // Introduced in DOM Level 2:
+ isSupported:function(feature, version){
+ return this.ownerDocument.implementation.hasFeature(feature,version);
+ },
+ // Introduced in DOM Level 2:
+ hasAttributes:function(){
+ return this.attributes.length>0;
+ },
+ lookupPrefix:function(namespaceURI){
+ var el = this;
+ while(el){
+ var map = el._nsMap;
+ //console.dir(map)
+ if(map){
+ for(var n in map){
+ if(map[n] == namespaceURI){
+ return n;
+ }
+ }
+ }
+ el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
+ }
+ return null;
+ },
+ // Introduced in DOM Level 3:
+ lookupNamespaceURI:function(prefix){
+ var el = this;
+ while(el){
+ var map = el._nsMap;
+ //console.dir(map)
+ if(map){
+ if(prefix in map){
+ return map[prefix] ;
+ }
+ }
+ el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
+ }
+ return null;
+ },
+ // Introduced in DOM Level 3:
+ isDefaultNamespace:function(namespaceURI){
+ var prefix = this.lookupPrefix(namespaceURI);
+ return prefix == null;
+ }
+};
+
+
+function _xmlEncoder(c){
+ return c == '<' && '<' ||
+ c == '>' && '>' ||
+ c == '&' && '&' ||
+ c == '"' && '"' ||
+ ''+c.charCodeAt()+';'
+}
+
+
+copy(NodeType,Node);
+copy(NodeType,Node.prototype);
+
+/**
+ * @param callback return true for continue,false for break
+ * @return boolean true: break visit;
+ */
+function _visitNode(node,callback){
+ if(callback(node)){
+ return true;
+ }
+ if(node = node.firstChild){
+ do{
+ if(_visitNode(node,callback)){return true}
+ }while(node=node.nextSibling)
+ }
+}
+
+
+
+function Document(){
+}
+function _onAddAttribute(doc,el,newAttr){
+ doc && doc._inc++;
+ var ns = newAttr.namespaceURI ;
+ if(ns == 'http://www.w3.org/2000/xmlns/'){
+ //update namespace
+ el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
+ }
+}
+function _onRemoveAttribute(doc,el,newAttr,remove){
+ doc && doc._inc++;
+ var ns = newAttr.namespaceURI ;
+ if(ns == 'http://www.w3.org/2000/xmlns/'){
+ //update namespace
+ delete el._nsMap[newAttr.prefix?newAttr.localName:'']
+ }
+}
+function _onUpdateChild(doc,el,newChild){
+ if(doc && doc._inc){
+ doc._inc++;
+ //update childNodes
+ var cs = el.childNodes;
+ if(newChild){
+ cs[cs.length++] = newChild;
+ }else{
+ //console.log(1)
+ var child = el.firstChild;
+ var i = 0;
+ while(child){
+ cs[i++] = child;
+ child =child.nextSibling;
+ }
+ cs.length = i;
+ }
+ }
+}
+
+/**
+ * attributes;
+ * children;
+ *
+ * writeable properties:
+ * nodeValue,Attr:value,CharacterData:data
+ * prefix
+ */
+function _removeChild(parentNode,child){
+ var previous = child.previousSibling;
+ var next = child.nextSibling;
+ if(previous){
+ previous.nextSibling = next;
+ }else{
+ parentNode.firstChild = next
+ }
+ if(next){
+ next.previousSibling = previous;
+ }else{
+ parentNode.lastChild = previous;
+ }
+ _onUpdateChild(parentNode.ownerDocument,parentNode);
+ return child;
+}
+/**
+ * preformance key(refChild == null)
+ */
+function _insertBefore(parentNode,newChild,nextChild){
+ var cp = newChild.parentNode;
+ if(cp){
+ cp.removeChild(newChild);//remove and update
+ }
+ if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
+ var newFirst = newChild.firstChild;
+ if (newFirst == null) {
+ return newChild;
+ }
+ var newLast = newChild.lastChild;
+ }else{
+ newFirst = newLast = newChild;
+ }
+ var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
+
+ newFirst.previousSibling = pre;
+ newLast.nextSibling = nextChild;
+
+
+ if(pre){
+ pre.nextSibling = newFirst;
+ }else{
+ parentNode.firstChild = newFirst;
+ }
+ if(nextChild == null){
+ parentNode.lastChild = newLast;
+ }else{
+ nextChild.previousSibling = newLast;
+ }
+ do{
+ newFirst.parentNode = parentNode;
+ }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
+ _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
+ //console.log(parentNode.lastChild.nextSibling == null)
+ if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
+ newChild.firstChild = newChild.lastChild = null;
+ }
+ return newChild;
+}
+function _appendSingleChild(parentNode,newChild){
+ var cp = newChild.parentNode;
+ if(cp){
+ var pre = parentNode.lastChild;
+ cp.removeChild(newChild);//remove and update
+ var pre = parentNode.lastChild;
+ }
+ var pre = parentNode.lastChild;
+ newChild.parentNode = parentNode;
+ newChild.previousSibling = pre;
+ newChild.nextSibling = null;
+ if(pre){
+ pre.nextSibling = newChild;
+ }else{
+ parentNode.firstChild = newChild;
+ }
+ parentNode.lastChild = newChild;
+ _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
+ return newChild;
+ //console.log("__aa",parentNode.lastChild.nextSibling == null)
+}
+Document.prototype = {
+ //implementation : null,
+ nodeName : '#document',
+ nodeType : DOCUMENT_NODE,
+ doctype : null,
+ documentElement : null,
+ _inc : 1,
+
+ insertBefore : function(newChild, refChild){//raises
+ if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
+ var child = newChild.firstChild;
+ while(child){
+ var next = child.nextSibling;
+ this.insertBefore(child,refChild);
+ child = next;
+ }
+ return newChild;
+ }
+ if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
+ this.documentElement = newChild;
+ }
+
+ return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
+ },
+ removeChild : function(oldChild){
+ if(this.documentElement == oldChild){
+ this.documentElement = null;
+ }
+ return _removeChild(this,oldChild);
+ },
+ // Introduced in DOM Level 2:
+ importNode : function(importedNode,deep){
+ return importNode(this,importedNode,deep);
+ },
+ // Introduced in DOM Level 2:
+ getElementById : function(id){
+ var rtv = null;
+ _visitNode(this.documentElement,function(node){
+ if(node.nodeType == ELEMENT_NODE){
+ if(node.getAttribute('id') == id){
+ rtv = node;
+ return true;
+ }
+ }
+ })
+ return rtv;
+ },
+
+ //document factory method:
+ createElement : function(tagName){
+ var node = new Element();
+ node.ownerDocument = this;
+ node.nodeName = tagName;
+ node.tagName = tagName;
+ node.childNodes = new NodeList();
+ var attrs = node.attributes = new NamedNodeMap();
+ attrs._ownerElement = node;
+ return node;
+ },
+ createDocumentFragment : function(){
+ var node = new DocumentFragment();
+ node.ownerDocument = this;
+ node.childNodes = new NodeList();
+ return node;
+ },
+ createTextNode : function(data){
+ var node = new Text();
+ node.ownerDocument = this;
+ node.appendData(data)
+ return node;
+ },
+ createComment : function(data){
+ var node = new Comment();
+ node.ownerDocument = this;
+ node.appendData(data)
+ return node;
+ },
+ createCDATASection : function(data){
+ var node = new CDATASection();
+ node.ownerDocument = this;
+ node.appendData(data)
+ return node;
+ },
+ createProcessingInstruction : function(target,data){
+ var node = new ProcessingInstruction();
+ node.ownerDocument = this;
+ node.tagName = node.target = target;
+ node.nodeValue= node.data = data;
+ return node;
+ },
+ createAttribute : function(name){
+ var node = new Attr();
+ node.ownerDocument = this;
+ node.name = name;
+ node.nodeName = name;
+ node.localName = name;
+ node.specified = true;
+ return node;
+ },
+ createEntityReference : function(name){
+ var node = new EntityReference();
+ node.ownerDocument = this;
+ node.nodeName = name;
+ return node;
+ },
+ // Introduced in DOM Level 2:
+ createElementNS : function(namespaceURI,qualifiedName){
+ var node = new Element();
+ var pl = qualifiedName.split(':');
+ var attrs = node.attributes = new NamedNodeMap();
+ node.childNodes = new NodeList();
+ node.ownerDocument = this;
+ node.nodeName = qualifiedName;
+ node.tagName = qualifiedName;
+ node.namespaceURI = namespaceURI;
+ if(pl.length == 2){
+ node.prefix = pl[0];
+ node.localName = pl[1];
+ }else{
+ //el.prefix = null;
+ node.localName = qualifiedName;
+ }
+ attrs._ownerElement = node;
+ return node;
+ },
+ // Introduced in DOM Level 2:
+ createAttributeNS : function(namespaceURI,qualifiedName){
+ var node = new Attr();
+ var pl = qualifiedName.split(':');
+ node.ownerDocument = this;
+ node.nodeName = qualifiedName;
+ node.name = qualifiedName;
+ node.namespaceURI = namespaceURI;
+ node.specified = true;
+ if(pl.length == 2){
+ node.prefix = pl[0];
+ node.localName = pl[1];
+ }else{
+ //el.prefix = null;
+ node.localName = qualifiedName;
+ }
+ return node;
+ }
+};
+_extends(Document,Node);
+
+
+function Element() {
+ this._nsMap = {};
+};
+Element.prototype = {
+ nodeType : ELEMENT_NODE,
+ hasAttribute : function(name){
+ return this.getAttributeNode(name)!=null;
+ },
+ getAttribute : function(name){
+ var attr = this.getAttributeNode(name);
+ return attr && attr.value || '';
+ },
+ getAttributeNode : function(name){
+ return this.attributes.getNamedItem(name);
+ },
+ setAttribute : function(name, value){
+ var attr = this.ownerDocument.createAttribute(name);
+ attr.value = attr.nodeValue = "" + value;
+ this.setAttributeNode(attr)
+ },
+ removeAttribute : function(name){
+ var attr = this.getAttributeNode(name)
+ attr && this.removeAttributeNode(attr);
+ },
+
+ //four real opeartion method
+ appendChild:function(newChild){
+ if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
+ return this.insertBefore(newChild,null);
+ }else{
+ return _appendSingleChild(this,newChild);
+ }
+ },
+ setAttributeNode : function(newAttr){
+ return this.attributes.setNamedItem(newAttr);
+ },
+ setAttributeNodeNS : function(newAttr){
+ return this.attributes.setNamedItemNS(newAttr);
+ },
+ removeAttributeNode : function(oldAttr){
+ //console.log(this == oldAttr.ownerElement)
+ return this.attributes.removeNamedItem(oldAttr.nodeName);
+ },
+ //get real attribute name,and remove it by removeAttributeNode
+ removeAttributeNS : function(namespaceURI, localName){
+ var old = this.getAttributeNodeNS(namespaceURI, localName);
+ old && this.removeAttributeNode(old);
+ },
+
+ hasAttributeNS : function(namespaceURI, localName){
+ return this.getAttributeNodeNS(namespaceURI, localName)!=null;
+ },
+ getAttributeNS : function(namespaceURI, localName){
+ var attr = this.getAttributeNodeNS(namespaceURI, localName);
+ return attr && attr.value || '';
+ },
+ setAttributeNS : function(namespaceURI, qualifiedName, value){
+ var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
+ attr.value = attr.nodeValue = "" + value;
+ this.setAttributeNode(attr)
+ },
+ getAttributeNodeNS : function(namespaceURI, localName){
+ return this.attributes.getNamedItemNS(namespaceURI, localName);
+ },
+
+ getElementsByTagName : function(tagName){
+ return new LiveNodeList(this,function(base){
+ var ls = [];
+ _visitNode(base,function(node){
+ if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
+ ls.push(node);
+ }
+ });
+ return ls;
+ });
+ },
+ getElementsByTagNameNS : function(namespaceURI, localName){
+ return new LiveNodeList(this,function(base){
+ var ls = [];
+ _visitNode(base,function(node){
+ if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
+ ls.push(node);
+ }
+ });
+ return ls;
+
+ });
+ }
+};
+Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
+Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
+
+
+_extends(Element,Node);
+function Attr() {
+};
+Attr.prototype.nodeType = ATTRIBUTE_NODE;
+_extends(Attr,Node);
+
+
+function CharacterData() {
+};
+CharacterData.prototype = {
+ data : '',
+ substringData : function(offset, count) {
+ return this.data.substring(offset, offset+count);
+ },
+ appendData: function(text) {
+ text = this.data+text;
+ this.nodeValue = this.data = text;
+ this.length = text.length;
+ },
+ insertData: function(offset,text) {
+ this.replaceData(offset,0,text);
+
+ },
+ appendChild:function(newChild){
+ throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
+ },
+ deleteData: function(offset, count) {
+ this.replaceData(offset,count,"");
+ },
+ replaceData: function(offset, count, text) {
+ var start = this.data.substring(0,offset);
+ var end = this.data.substring(offset+count);
+ text = start + text + end;
+ this.nodeValue = this.data = text;
+ this.length = text.length;
+ }
+}
+_extends(CharacterData,Node);
+function Text() {
+};
+Text.prototype = {
+ nodeName : "#text",
+ nodeType : TEXT_NODE,
+ splitText : function(offset) {
+ var text = this.data;
+ var newText = text.substring(offset);
+ text = text.substring(0, offset);
+ this.data = this.nodeValue = text;
+ this.length = text.length;
+ var newNode = this.ownerDocument.createTextNode(newText);
+ if(this.parentNode){
+ this.parentNode.insertBefore(newNode, this.nextSibling);
+ }
+ return newNode;
+ }
+}
+_extends(Text,CharacterData);
+function Comment() {
+};
+Comment.prototype = {
+ nodeName : "#comment",
+ nodeType : COMMENT_NODE
+}
+_extends(Comment,CharacterData);
+
+function CDATASection() {
+};
+CDATASection.prototype = {
+ nodeName : "#cdata-section",
+ nodeType : CDATA_SECTION_NODE
+}
+_extends(CDATASection,CharacterData);
+
+
+function DocumentType() {
+};
+DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
+_extends(DocumentType,Node);
+
+function Notation() {
+};
+Notation.prototype.nodeType = NOTATION_NODE;
+_extends(Notation,Node);
+
+function Entity() {
+};
+Entity.prototype.nodeType = ENTITY_NODE;
+_extends(Entity,Node);
+
+function EntityReference() {
+};
+EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
+_extends(EntityReference,Node);
+
+function DocumentFragment() {
+};
+DocumentFragment.prototype.nodeName = "#document-fragment";
+DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
+_extends(DocumentFragment,Node);
+
+
+function ProcessingInstruction() {
+}
+ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
+_extends(ProcessingInstruction,Node);
+function XMLSerializer(){}
+XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
+ return nodeSerializeToString.call(node,isHtml,nodeFilter);
+}
+Node.prototype.toString = nodeSerializeToString;
+function nodeSerializeToString(isHtml,nodeFilter){
+ var buf = [];
+ var refNode = this.nodeType == 9?this.documentElement:this;
+ var prefix = refNode.prefix;
+ var uri = refNode.namespaceURI;
+
+ if(uri && prefix == null){
+ //console.log(prefix)
+ var prefix = refNode.lookupPrefix(uri);
+ if(prefix == null){
+ //isHTML = true;
+ var visibleNamespaces=[
+ {namespace:uri,prefix:null}
+ //{namespace:uri,prefix:''}
+ ]
+ }
+ }
+ serializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);
+ //console.log('###',this.nodeType,uri,prefix,buf.join(''))
+ return buf.join('');
+}
+function needNamespaceDefine(node,isHTML, visibleNamespaces) {
+ var prefix = node.prefix||'';
+ var uri = node.namespaceURI;
+ if (!prefix && !uri){
+ return false;
+ }
+ if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
+ || uri == 'http://www.w3.org/2000/xmlns/'){
+ return false;
+ }
+
+ var i = visibleNamespaces.length
+ //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
+ while (i--) {
+ var ns = visibleNamespaces[i];
+ // get namespace prefix
+ //console.log(node.nodeType,node.tagName,ns.prefix,prefix)
+ if (ns.prefix == prefix){
+ return ns.namespace != uri;
+ }
+ }
+ //console.log(isHTML,uri,prefix=='')
+ //if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
+ // return false;
+ //}
+ //node.flag = '11111'
+ //console.error(3,true,node.flag,node.prefix,node.namespaceURI)
+ return true;
+}
+function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
+ if(nodeFilter){
+ node = nodeFilter(node);
+ if(node){
+ if(typeof node == 'string'){
+ buf.push(node);
+ return;
+ }
+ }else{
+ return;
+ }
+ //buf.sort.apply(attrs, attributeSorter);
+ }
+ switch(node.nodeType){
+ case ELEMENT_NODE:
+ if (!visibleNamespaces) visibleNamespaces = [];
+ var startVisibleNamespaces = visibleNamespaces.length;
+ var attrs = node.attributes;
+ var len = attrs.length;
+ var child = node.firstChild;
+ var nodeName = node.tagName;
+
+ isHTML = (htmlns === node.namespaceURI) ||isHTML
+ buf.push('<',nodeName);
+
+
+
+ for(var i=0;i');
+ //if is cdata child node
+ if(isHTML && /^script$/i.test(nodeName)){
+ while(child){
+ if(child.data){
+ buf.push(child.data);
+ }else{
+ serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
+ }
+ child = child.nextSibling;
+ }
+ }else
+ {
+ while(child){
+ serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
+ child = child.nextSibling;
+ }
+ }
+ buf.push('',nodeName,'>');
+ }else{
+ buf.push('/>');
+ }
+ // remove added visible namespaces
+ //visibleNamespaces.length = startVisibleNamespaces;
+ return;
+ case DOCUMENT_NODE:
+ case DOCUMENT_FRAGMENT_NODE:
+ var child = node.firstChild;
+ while(child){
+ serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
+ child = child.nextSibling;
+ }
+ return;
+ case ATTRIBUTE_NODE:
+ return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
+ case TEXT_NODE:
+ return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
+ case CDATA_SECTION_NODE:
+ return buf.push( '');
+ case COMMENT_NODE:
+ return buf.push( "");
+ case DOCUMENT_TYPE_NODE:
+ var pubid = node.publicId;
+ var sysid = node.systemId;
+ buf.push('');
+ }else if(sysid && sysid!='.'){
+ buf.push(' SYSTEM "',sysid,'">');
+ }else{
+ var sub = node.internalSubset;
+ if(sub){
+ buf.push(" [",sub,"]");
+ }
+ buf.push(">");
+ }
+ return;
+ case PROCESSING_INSTRUCTION_NODE:
+ return buf.push( "",node.target," ",node.data,"?>");
+ case ENTITY_REFERENCE_NODE:
+ return buf.push( '&',node.nodeName,';');
+ //case ENTITY_NODE:
+ //case NOTATION_NODE:
+ default:
+ buf.push('??',node.nodeName);
+ }
+}
+function importNode(doc,node,deep){
+ var node2;
+ switch (node.nodeType) {
+ case ELEMENT_NODE:
+ node2 = node.cloneNode(false);
+ node2.ownerDocument = doc;
+ //var attrs = node2.attributes;
+ //var len = attrs.length;
+ //for(var i=0;i=0.1"
+ },
+ "homepage": "https://github.com/jindw/xmldom",
+ "keywords": [
+ "w3c",
+ "dom",
+ "xml",
+ "parser",
+ "javascript",
+ "DOMParser",
+ "XMLSerializer"
+ ],
+ "licenses": [
+ {
+ "type": "LGPL",
+ "url": "http://www.gnu.org/licenses/lgpl.html",
+ "MIT": "http://opensource.org/licenses/MIT"
+ }
+ ],
+ "main": "./dom-parser.js",
+ "maintainers": [
+ {
+ "name": "jindw",
+ "email": "jindw@xidea.org",
+ "url": "http://www.xidea.org"
+ }
+ ],
+ "name": "xmldom",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jindw/xmldom.git"
+ },
+ "scripts": {
+ "test": "proof platform win32 && proof test */*/*.t.js || t/test"
+ },
+ "version": "0.1.27"
+}
diff --git a/node_modules/xmldom/readme.md b/node_modules/xmldom/readme.md
new file mode 100644
index 00000000..f832c448
--- /dev/null
+++ b/node_modules/xmldom/readme.md
@@ -0,0 +1,219 @@
+# XMLDOM [](http://travis-ci.org/bigeasy/xmldom) [](https://coveralls.io/r/bigeasy/xmldom) [](http://badge.fury.io/js/xmldom)
+
+A JavaScript implementation of W3C DOM for Node.js, Rhino and the browser. Fully
+compatible with `W3C DOM level2`; and some compatible with `level3`. Supports
+`DOMParser` and `XMLSerializer` interface such as in browser.
+
+Install:
+-------
+>npm install xmldom
+
+Example:
+====
+```javascript
+var DOMParser = require('xmldom').DOMParser;
+var doc = new DOMParser().parseFromString(
+ '\n'+
+ '\ttest\n'+
+ '\t\n'+
+ '\t\n'+
+ ''
+ ,'text/xml');
+doc.documentElement.setAttribute('x','y');
+doc.documentElement.setAttributeNS('./lite','c:x','y2');
+var nsAttr = doc.documentElement.getAttributeNS('./lite','x')
+console.info(nsAttr)
+console.info(doc)
+```
+API Reference
+=====
+
+ * [DOMParser](https://developer.mozilla.org/en/DOMParser):
+
+ ```javascript
+ parseFromString(xmlsource,mimeType)
+ ```
+ * **options extension** _by xmldom_(not BOM standard!!)
+
+ ```javascript
+ //added the options argument
+ new DOMParser(options)
+
+ //errorHandler is supported
+ new DOMParser({
+ /**
+ * locator is always need for error position info
+ */
+ locator:{},
+ /**
+ * you can override the errorHandler for xml parser
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
+ */
+ errorHandler:{warning:function(w){console.warn(w)},error:callback,fatalError:callback}
+ //only callback model
+ //errorHandler:function(level,msg){console.log(level,msg)}
+ })
+
+ ```
+
+ * [XMLSerializer](https://developer.mozilla.org/en/XMLSerializer)
+
+ ```javascript
+ serializeToString(node)
+ ```
+DOM level2 method and attribute:
+------
+
+ * [Node](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247)
+
+ attribute:
+ nodeValue|prefix
+ readonly attribute:
+ nodeName|nodeType|parentNode|childNodes|firstChild|lastChild|previousSibling|nextSibling|attributes|ownerDocument|namespaceURI|localName
+ method:
+ insertBefore(newChild, refChild)
+ replaceChild(newChild, oldChild)
+ removeChild(oldChild)
+ appendChild(newChild)
+ hasChildNodes()
+ cloneNode(deep)
+ normalize()
+ isSupported(feature, version)
+ hasAttributes()
+
+ * [DOMImplementation](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-102161490)
+
+ method:
+ hasFeature(feature, version)
+ createDocumentType(qualifiedName, publicId, systemId)
+ createDocument(namespaceURI, qualifiedName, doctype)
+
+ * [Document](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document) : Node
+
+ readonly attribute:
+ doctype|implementation|documentElement
+ method:
+ createElement(tagName)
+ createDocumentFragment()
+ createTextNode(data)
+ createComment(data)
+ createCDATASection(data)
+ createProcessingInstruction(target, data)
+ createAttribute(name)
+ createEntityReference(name)
+ getElementsByTagName(tagname)
+ importNode(importedNode, deep)
+ createElementNS(namespaceURI, qualifiedName)
+ createAttributeNS(namespaceURI, qualifiedName)
+ getElementsByTagNameNS(namespaceURI, localName)
+ getElementById(elementId)
+
+ * [DocumentFragment](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-B63ED1A3) : Node
+ * [Element](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-745549614) : Node
+
+ readonly attribute:
+ tagName
+ method:
+ getAttribute(name)
+ setAttribute(name, value)
+ removeAttribute(name)
+ getAttributeNode(name)
+ setAttributeNode(newAttr)
+ removeAttributeNode(oldAttr)
+ getElementsByTagName(name)
+ getAttributeNS(namespaceURI, localName)
+ setAttributeNS(namespaceURI, qualifiedName, value)
+ removeAttributeNS(namespaceURI, localName)
+ getAttributeNodeNS(namespaceURI, localName)
+ setAttributeNodeNS(newAttr)
+ getElementsByTagNameNS(namespaceURI, localName)
+ hasAttribute(name)
+ hasAttributeNS(namespaceURI, localName)
+
+ * [Attr](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-637646024) : Node
+
+ attribute:
+ value
+ readonly attribute:
+ name|specified|ownerElement
+
+ * [NodeList](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177)
+
+ readonly attribute:
+ length
+ method:
+ item(index)
+
+ * [NamedNodeMap](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1780488922)
+
+ readonly attribute:
+ length
+ method:
+ getNamedItem(name)
+ setNamedItem(arg)
+ removeNamedItem(name)
+ item(index)
+ getNamedItemNS(namespaceURI, localName)
+ setNamedItemNS(arg)
+ removeNamedItemNS(namespaceURI, localName)
+
+ * [CharacterData](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-FF21A306) : Node
+
+ method:
+ substringData(offset, count)
+ appendData(arg)
+ insertData(offset, arg)
+ deleteData(offset, count)
+ replaceData(offset, count, arg)
+
+ * [Text](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1312295772) : CharacterData
+
+ method:
+ splitText(offset)
+
+ * [CDATASection](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-667469212)
+ * [Comment](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1728279322) : CharacterData
+
+ * [DocumentType](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-412266927)
+
+ readonly attribute:
+ name|entities|notations|publicId|systemId|internalSubset
+
+ * Notation : Node
+
+ readonly attribute:
+ publicId|systemId
+
+ * Entity : Node
+
+ readonly attribute:
+ publicId|systemId|notationName
+
+ * EntityReference : Node
+ * ProcessingInstruction : Node
+
+ attribute:
+ data
+ readonly attribute:
+ target
+
+DOM level 3 support:
+-----
+
+ * [Node](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent)
+
+ attribute:
+ textContent
+ method:
+ isDefaultNamespace(namespaceURI){
+ lookupNamespaceURI(prefix)
+
+DOM extension by xmldom
+---
+ * [Node] Source position extension;
+
+ attribute:
+ //Numbered starting from '1'
+ lineNumber
+ //Numbered starting from '1'
+ columnNumber
diff --git a/node_modules/xmldom/sax.js b/node_modules/xmldom/sax.js
new file mode 100644
index 00000000..b33635f6
--- /dev/null
+++ b/node_modules/xmldom/sax.js
@@ -0,0 +1,633 @@
+//[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
+//[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
+//[5] Name ::= NameStartChar (NameChar)*
+var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
+var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
+var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
+//var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
+//var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
+
+//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
+//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
+var S_TAG = 0;//tag name offerring
+var S_ATTR = 1;//attr name offerring
+var S_ATTR_SPACE=2;//attr name end and space offer
+var S_EQ = 3;//=space?
+var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
+var S_ATTR_END = 5;//attr value end and no space(quot end)
+var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
+var S_TAG_CLOSE = 7;//closed el
+
+function XMLReader(){
+
+}
+
+XMLReader.prototype = {
+ parse:function(source,defaultNSMap,entityMap){
+ var domBuilder = this.domBuilder;
+ domBuilder.startDocument();
+ _copy(defaultNSMap ,defaultNSMap = {})
+ parse(source,defaultNSMap,entityMap,
+ domBuilder,this.errorHandler);
+ domBuilder.endDocument();
+ }
+}
+function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
+ function fixedFromCharCode(code) {
+ // String.prototype.fromCharCode does not supports
+ // > 2 bytes unicode chars directly
+ if (code > 0xffff) {
+ code -= 0x10000;
+ var surrogate1 = 0xd800 + (code >> 10)
+ , surrogate2 = 0xdc00 + (code & 0x3ff);
+
+ return String.fromCharCode(surrogate1, surrogate2);
+ } else {
+ return String.fromCharCode(code);
+ }
+ }
+ function entityReplacer(a){
+ var k = a.slice(1,-1);
+ if(k in entityMap){
+ return entityMap[k];
+ }else if(k.charAt(0) === '#'){
+ return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
+ }else{
+ errorHandler.error('entity not found:'+a);
+ return a;
+ }
+ }
+ function appendText(end){//has some bugs
+ if(end>start){
+ var xt = source.substring(start,end).replace(/?\w+;/g,entityReplacer);
+ locator&&position(start);
+ domBuilder.characters(xt,0,end-start);
+ start = end
+ }
+ }
+ function position(p,m){
+ while(p>=lineEnd && (m = linePattern.exec(source))){
+ lineStart = m.index;
+ lineEnd = lineStart + m[0].length;
+ locator.lineNumber++;
+ //console.log('line++:',locator,startPos,endPos)
+ }
+ locator.columnNumber = p-lineStart+1;
+ }
+ var lineStart = 0;
+ var lineEnd = 0;
+ var linePattern = /.*(?:\r\n?|\n)|.*$/g
+ var locator = domBuilder.locator;
+
+ var parseStack = [{currentNSMap:defaultNSMapCopy}]
+ var closeMap = {};
+ var start = 0;
+ while(true){
+ try{
+ var tagStart = source.indexOf('<',start);
+ if(tagStart<0){
+ if(!source.substr(start).match(/^\s*$/)){
+ var doc = domBuilder.doc;
+ var text = doc.createTextNode(source.substr(start));
+ doc.appendChild(text);
+ domBuilder.currentElement = text;
+ }
+ return;
+ }
+ if(tagStart>start){
+ appendText(tagStart);
+ }
+ switch(source.charAt(tagStart+1)){
+ case '/':
+ var end = source.indexOf('>',tagStart+3);
+ var tagName = source.substring(tagStart+2,end);
+ var config = parseStack.pop();
+ if(end<0){
+
+ tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
+ //console.error('#@@@@@@'+tagName)
+ errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
+ end = tagStart+1+tagName.length;
+ }else if(tagName.match(/\s)){
+ tagName = tagName.replace(/[\s<].*/,'');
+ errorHandler.error("end tag name: "+tagName+' maybe not complete');
+ end = tagStart+1+tagName.length;
+ }
+ //console.error(parseStack.length,parseStack)
+ //console.error(config);
+ var localNSMap = config.localNSMap;
+ var endMatch = config.tagName == tagName;
+ var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
+ if(endIgnoreCaseMach){
+ domBuilder.endElement(config.uri,config.localName,tagName);
+ if(localNSMap){
+ for(var prefix in localNSMap){
+ domBuilder.endPrefixMapping(prefix) ;
+ }
+ }
+ if(!endMatch){
+ errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
+ }
+ }else{
+ parseStack.push(config)
+ }
+
+ end++;
+ break;
+ // end elment
+ case '?':// ...?>
+ locator&&position(tagStart);
+ end = parseInstruction(source,tagStart,domBuilder);
+ break;
+ case '!':// start){
+ start = end;
+ }else{
+ //TODO: 这里有可能sax回退,有位置错误风险
+ appendText(Math.max(tagStart,start)+1);
+ }
+ }
+}
+function copyLocator(f,t){
+ t.lineNumber = f.lineNumber;
+ t.columnNumber = f.columnNumber;
+ return t;
+}
+
+/**
+ * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
+ * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
+ */
+function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
+ var attrName;
+ var value;
+ var p = ++start;
+ var s = S_TAG;//status
+ while(true){
+ var c = source.charAt(p);
+ switch(c){
+ case '=':
+ if(s === S_ATTR){//attrName
+ attrName = source.slice(start,p);
+ s = S_EQ;
+ }else if(s === S_ATTR_SPACE){
+ s = S_EQ;
+ }else{
+ //fatalError: equal must after attrName or space after attrName
+ throw new Error('attribute equal must after attrName');
+ }
+ break;
+ case '\'':
+ case '"':
+ if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
+ ){//equal
+ if(s === S_ATTR){
+ errorHandler.warning('attribute value must after "="')
+ attrName = source.slice(start,p)
+ }
+ start = p+1;
+ p = source.indexOf(c,start)
+ if(p>0){
+ value = source.slice(start,p).replace(/?\w+;/g,entityReplacer);
+ el.add(attrName,value,start-1);
+ s = S_ATTR_END;
+ }else{
+ //fatalError: no end quot match
+ throw new Error('attribute value no end \''+c+'\' match');
+ }
+ }else if(s == S_ATTR_NOQUOT_VALUE){
+ value = source.slice(start,p).replace(/?\w+;/g,entityReplacer);
+ //console.log(attrName,value,start,p)
+ el.add(attrName,value,start);
+ //console.dir(el)
+ errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
+ start = p+1;
+ s = S_ATTR_END
+ }else{
+ //fatalError: no equal before
+ throw new Error('attribute value must after "="');
+ }
+ break;
+ case '/':
+ switch(s){
+ case S_TAG:
+ el.setTagName(source.slice(start,p));
+ case S_ATTR_END:
+ case S_TAG_SPACE:
+ case S_TAG_CLOSE:
+ s =S_TAG_CLOSE;
+ el.closed = true;
+ case S_ATTR_NOQUOT_VALUE:
+ case S_ATTR:
+ case S_ATTR_SPACE:
+ break;
+ //case S_EQ:
+ default:
+ throw new Error("attribute invalid close char('/')")
+ }
+ break;
+ case ''://end document
+ //throw new Error('unexpected end of input')
+ errorHandler.error('unexpected end of input');
+ if(s == S_TAG){
+ el.setTagName(source.slice(start,p));
+ }
+ return p;
+ case '>':
+ switch(s){
+ case S_TAG:
+ el.setTagName(source.slice(start,p));
+ case S_ATTR_END:
+ case S_TAG_SPACE:
+ case S_TAG_CLOSE:
+ break;//normal
+ case S_ATTR_NOQUOT_VALUE://Compatible state
+ case S_ATTR:
+ value = source.slice(start,p);
+ if(value.slice(-1) === '/'){
+ el.closed = true;
+ value = value.slice(0,-1)
+ }
+ case S_ATTR_SPACE:
+ if(s === S_ATTR_SPACE){
+ value = attrName;
+ }
+ if(s == S_ATTR_NOQUOT_VALUE){
+ errorHandler.warning('attribute "'+value+'" missed quot(")!!');
+ el.add(attrName,value.replace(/?\w+;/g,entityReplacer),start)
+ }else{
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
+ errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
+ }
+ el.add(value,value,start)
+ }
+ break;
+ case S_EQ:
+ throw new Error('attribute value missed!!');
+ }
+// console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
+ return p;
+ /*xml space '\x20' | #x9 | #xD | #xA; */
+ case '\u0080':
+ c = ' ';
+ default:
+ if(c<= ' '){//space
+ switch(s){
+ case S_TAG:
+ el.setTagName(source.slice(start,p));//tagName
+ s = S_TAG_SPACE;
+ break;
+ case S_ATTR:
+ attrName = source.slice(start,p)
+ s = S_ATTR_SPACE;
+ break;
+ case S_ATTR_NOQUOT_VALUE:
+ var value = source.slice(start,p).replace(/?\w+;/g,entityReplacer);
+ errorHandler.warning('attribute "'+value+'" missed quot(")!!');
+ el.add(attrName,value,start)
+ case S_ATTR_END:
+ s = S_TAG_SPACE;
+ break;
+ //case S_TAG_SPACE:
+ //case S_EQ:
+ //case S_ATTR_SPACE:
+ // void();break;
+ //case S_TAG_CLOSE:
+ //ignore warning
+ }
+ }else{//not space
+//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
+//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
+ switch(s){
+ //case S_TAG:void();break;
+ //case S_ATTR:void();break;
+ //case S_ATTR_NOQUOT_VALUE:void();break;
+ case S_ATTR_SPACE:
+ var tagName = el.tagName;
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
+ errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
+ }
+ el.add(attrName,attrName,start);
+ start = p;
+ s = S_ATTR;
+ break;
+ case S_ATTR_END:
+ errorHandler.warning('attribute space is required"'+attrName+'"!!')
+ case S_TAG_SPACE:
+ s = S_ATTR;
+ start = p;
+ break;
+ case S_EQ:
+ s = S_ATTR_NOQUOT_VALUE;
+ start = p;
+ break;
+ case S_TAG_CLOSE:
+ throw new Error("elements closed character '/' and '>' must be connected to");
+ }
+ }
+ }//end outer switch
+ //console.log('p++',p)
+ p++;
+ }
+}
+/**
+ * @return true if has new namespace define
+ */
+function appendElement(el,domBuilder,currentNSMap){
+ var tagName = el.tagName;
+ var localNSMap = null;
+ //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
+ var i = el.length;
+ while(i--){
+ var a = el[i];
+ var qName = a.qName;
+ var value = a.value;
+ var nsp = qName.indexOf(':');
+ if(nsp>0){
+ var prefix = a.prefix = qName.slice(0,nsp);
+ var localName = qName.slice(nsp+1);
+ var nsPrefix = prefix === 'xmlns' && localName
+ }else{
+ localName = qName;
+ prefix = null
+ nsPrefix = qName === 'xmlns' && ''
+ }
+ //can not set prefix,because prefix !== ''
+ a.localName = localName ;
+ //prefix == null for no ns prefix attribute
+ if(nsPrefix !== false){//hack!!
+ if(localNSMap == null){
+ localNSMap = {}
+ //console.log(currentNSMap,0)
+ _copy(currentNSMap,currentNSMap={})
+ //console.log(currentNSMap,1)
+ }
+ currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
+ a.uri = 'http://www.w3.org/2000/xmlns/'
+ domBuilder.startPrefixMapping(nsPrefix, value)
+ }
+ }
+ var i = el.length;
+ while(i--){
+ a = el[i];
+ var prefix = a.prefix;
+ if(prefix){//no prefix attribute has no namespace
+ if(prefix === 'xml'){
+ a.uri = 'http://www.w3.org/XML/1998/namespace';
+ }if(prefix !== 'xmlns'){
+ a.uri = currentNSMap[prefix || '']
+
+ //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
+ }
+ }
+ }
+ var nsp = tagName.indexOf(':');
+ if(nsp>0){
+ prefix = el.prefix = tagName.slice(0,nsp);
+ localName = el.localName = tagName.slice(nsp+1);
+ }else{
+ prefix = null;//important!!
+ localName = el.localName = tagName;
+ }
+ //no prefix element has default namespace
+ var ns = el.uri = currentNSMap[prefix || ''];
+ domBuilder.startElement(ns,localName,tagName,el);
+ //endPrefixMapping and startPrefixMapping have not any help for dom builder
+ //localNSMap = null
+ if(el.closed){
+ domBuilder.endElement(ns,localName,tagName);
+ if(localNSMap){
+ for(prefix in localNSMap){
+ domBuilder.endPrefixMapping(prefix)
+ }
+ }
+ }else{
+ el.currentNSMap = currentNSMap;
+ el.localNSMap = localNSMap;
+ //parseStack.push(el);
+ return true;
+ }
+}
+function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
+ if(/^(?:script|textarea)$/i.test(tagName)){
+ var elEndStart = source.indexOf(''+tagName+'>',elStartEnd);
+ var text = source.substring(elStartEnd+1,elEndStart);
+ if(/[&<]/.test(text)){
+ if(/^script$/i.test(tagName)){
+ //if(!/\]\]>/.test(text)){
+ //lexHandler.startCDATA();
+ domBuilder.characters(text,0,text.length);
+ //lexHandler.endCDATA();
+ return elEndStart;
+ //}
+ }//}else{//text area
+ text = text.replace(/?\w+;/g,entityReplacer);
+ domBuilder.characters(text,0,text.length);
+ return elEndStart;
+ //}
+
+ }
+ }
+ return elStartEnd+1;
+}
+function fixSelfClosed(source,elStartEnd,tagName,closeMap){
+ //if(tagName in closeMap){
+ var pos = closeMap[tagName];
+ if(pos == null){
+ //console.log(tagName)
+ pos = source.lastIndexOf(''+tagName+'>')
+ if(pos',start+4);
+ //append comment source.substring(4,end)//Harry Potter';
+ var doc = new dom().parseFromString(xml);
+ var nodes = xpath.select('//title', doc);
+ assert.equal('title', nodes[0].localName);
+ assert.equal('Harry Potter', nodes[0].firstChild.data);
+ assert.equal('Harry Potter', nodes[0].toString());
+
+ var nodes2 = xpath.select('//node()', doc);
+ assert.equal(7, nodes2.length);
+
+ var pis = xpath.select("/processing-instruction('series')", doc);
+ assert.equal(2, pis.length);
+ assert.equal('books="7"', pis[1].data);
+
+ test.done();
+ },
+
+ 'select single node': function(test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+
+ assert.equal('title', xpath.select('//title[1]', doc)[0].localName);
+
+ test.done();
+ },
+
+ 'select text node': function (test) {
+ var xml = 'HarryPotter';
+ var doc = new dom().parseFromString(xml);
+
+ assert.deepEqual('book', xpath.select('local-name(/book)', doc));
+ assert.deepEqual('Harry,Potter', xpath.select('//title/text()', doc).toString());
+
+ test.done();
+ },
+
+ 'select number value': function(test) {
+ var xml = 'HarryPotter';
+ var doc = new dom().parseFromString(xml);
+
+ assert.deepEqual(2, xpath.select('count(//title)', doc));
+
+ test.done();
+ },
+
+ 'select xpath with namespaces': function (test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+
+ var nodes = xpath.select('//*[local-name(.)="title" and namespace-uri(.)="myns"]', doc);
+ assert.equal('title', nodes[0].localName);
+ assert.equal('myns', nodes[0].namespaceURI) ;
+
+ var nodes2 = xpath.select('/*/title', doc);
+
+ assert.equal(0, nodes2.length);
+
+ test.done();
+ },
+
+ 'select xpath with namespaces, using a resolver': function (test) {
+ var xml = 'NarniaHarry PotterJKR';
+ var doc = new dom().parseFromString(xml);
+
+ var resolver = {
+ mappings: {
+ 'testns': 'http://example.com/test'
+ },
+ lookupNamespaceURI: function(prefix) {
+ return this.mappings[prefix];
+ }
+ }
+
+ var nodes = xpath.selectWithResolver('//testns:title/text()', doc, resolver);
+ assert.equal('Harry Potter', xpath.selectWithResolver('//testns:title/text()', doc, resolver)[0].nodeValue);
+ assert.equal('JKR', xpath.selectWithResolver('//testns:field[@testns:type="author"]/text()', doc, resolver)[0].nodeValue);
+
+ var nodes2 = xpath.selectWithResolver('/*/testns:*', doc, resolver);
+
+ assert.equal(2, nodes2.length);
+
+ test.done();
+ },
+
+ 'select xpath with default namespace, using a resolver': function (test) {
+ var xml = 'Harry PotterJKR';
+ var doc = new dom().parseFromString(xml);
+
+ var resolver = {
+ mappings: {
+ 'testns': 'http://example.com/test'
+ },
+ lookupNamespaceURI: function(prefix) {
+ return this.mappings[prefix];
+ }
+ }
+
+ var nodes = xpath.selectWithResolver('//testns:title/text()', doc, resolver);
+ assert.equal('Harry Potter', xpath.selectWithResolver('//testns:title/text()', doc, resolver)[0].nodeValue);
+ assert.equal('JKR', xpath.selectWithResolver('//testns:field[@type="author"]/text()', doc, resolver)[0].nodeValue);
+
+ test.done();
+ },
+
+ 'select xpath with namespaces, prefixes different in xml and xpath, using a resolver': function (test) {
+ var xml = 'Harry PotterJKR';
+ var doc = new dom().parseFromString(xml);
+
+ var resolver = {
+ mappings: {
+ 'ns': 'http://example.com/test'
+ },
+ lookupNamespaceURI: function(prefix) {
+ return this.mappings[prefix];
+ }
+ }
+
+ var nodes = xpath.selectWithResolver('//ns:title/text()', doc, resolver);
+ assert.equal('Harry Potter', xpath.selectWithResolver('//ns:title/text()', doc, resolver)[0].nodeValue);
+ assert.equal('JKR', xpath.selectWithResolver('//ns:field[@ns:type="author"]/text()', doc, resolver)[0].nodeValue);
+
+ test.done();
+ },
+
+ 'select xpath with namespaces, using namespace mappings': function (test) {
+ var xml = 'Harry PotterJKR';
+ var doc = new dom().parseFromString(xml);
+ var select = xpath.useNamespaces({'testns': 'http://example.com/test'});
+
+ assert.equal('Harry Potter', select('//testns:title/text()', doc)[0].nodeValue);
+ assert.equal('JKR', select('//testns:field[@testns:type="author"]/text()', doc)[0].nodeValue);
+
+ test.done();
+ },
+
+
+ 'select attribute': function (test) {
+ var xml = '';
+ var doc = new dom().parseFromString(xml);
+
+ var author = xpath.select1('/author/@name', doc).value;
+ assert.equal('J. K. Rowling', author);
+
+ test.done();
+ }
+
+ ,'select with multiple predicates': function (test) {
+ var xml = '';
+ var doc = new dom().parseFromString(xml);
+
+ var characters = xpath.select('/*/character[@sex = "M"][@age > 40]/@name', doc);
+
+ assert.equal(1, characters.length);
+ assert.equal('Snape', characters[0].textContent);
+
+ test.done();
+ }
+
+ // https://github.com/goto100/xpath/issues/37
+ ,'select multiple attributes': function (test) {
+ var xml = '';
+ var doc = new dom().parseFromString(xml);
+
+ var authors = xpath.select('/authors/author/@name', doc);
+ assert.equal(2, authors.length);
+ assert.equal('J. K. Rowling', authors[0].value);
+
+ // https://github.com/goto100/xpath/issues/41
+ doc = new dom().parseFromString('');
+ var nodes = xpath.select("/chapters/chapter/@v", doc);
+ var values = nodes.map(function(n) { return n.value; });
+
+ assert.equal(3, values.length);
+ assert.equal("1", values[0]);
+ assert.equal("2", values[1]);
+ assert.equal("3", values[2]);
+
+ test.done();
+ }
+
+ ,'XPathException acts like Error': function (test) {
+ try {
+ xpath.evaluate('1', null, null, null);
+ assert.fail(null, null, 'evaluate() should throw exception');
+ } catch (e) {
+ assert.ok('code' in e, 'must have a code');
+ assert.ok('stack' in e, 'must have a stack');
+ }
+
+ test.done();
+ },
+
+ 'string() with no arguments': function (test) {
+ var doc = new dom().parseFromString('Harry Potter');
+
+ var rootElement = xpath.select1('/book', doc);
+ assert.ok(rootElement, 'rootElement is null');
+
+ assert.equal('Harry Potter', xpath.select1('string()', doc));
+
+ test.done();
+ },
+
+ 'string value of document fragment': function (test) {
+ var doc = new dom().parseFromString('');
+ var docFragment = doc.createDocumentFragment();
+
+ var el = doc.createElement("book");
+ docFragment.appendChild(el);
+
+ var testValue = "Harry Potter";
+
+ el.appendChild(doc.createTextNode(testValue));
+
+ assert.equal(testValue, xpath.select1("string()", docFragment));
+
+ test.done();
+ },
+
+ 'compare string of a number with a number': function (test) {
+ assert.ok(xpath.select1('"000" = 0'), '000');
+ assert.ok(xpath.select1('"45.0" = 45'), '45');
+
+ test.done();
+ },
+
+ 'string(boolean) is a string': function (test) {
+ assert.equal('string', typeof xpath.select1('string(true())'));
+ assert.equal('string', typeof xpath.select1('string(false())'));
+ assert.equal('string', typeof xpath.select1('string(1 = 2)'));
+ assert.ok(xpath.select1('"true" = string(true())'), '"true" = string(true())');
+
+ test.done();
+ },
+
+ 'string should downcast to boolean': function (test) {
+ assert.equal(false, xpath.select1('"false" = false()'), '"false" = false()');
+ assert.equal(true, xpath.select1('"a" = true()'), '"a" = true()');
+ assert.equal(true, xpath.select1('"" = false()'), '"" = false()');
+
+ test.done();
+ },
+
+ 'string(number) is a string': function (test) {
+ assert.equal('string', typeof xpath.select1('string(45)'));
+ assert.ok(xpath.select1('"45" = string(45)'), '"45" = string(45)');
+
+ test.done();
+ },
+
+ 'correct string to number conversion': function (test) {
+ assert.equal(45.2, xpath.select1('number("45.200")'));
+ assert.equal(55.0, xpath.select1('number("000055")'));
+ assert.equal(65.0, xpath.select1('number(" 65 ")'));
+
+ assert.equal(true, xpath.select1('"" != 0'), '"" != 0');
+ assert.equal(false, xpath.select1('"" = 0'), '"" = 0');
+ assert.equal(false, xpath.select1('0 = ""'), '0 = ""');
+ assert.equal(false, xpath.select1('0 = " "'), '0 = " "');
+
+ assert.ok(Number.isNaN(xpath.select('number("")')), 'number("")');
+ assert.ok(Number.isNaN(xpath.select('number("45.8g")')), 'number("45.8g")');
+ assert.ok(Number.isNaN(xpath.select('number("2e9")')), 'number("2e9")');
+ assert.ok(Number.isNaN(xpath.select('number("+33")')), 'number("+33")');
+
+ test.done();
+ }
+
+ ,'correct number to string conversion': function (test) {
+ assert.equal('0.0000000000000000000000005250000000000001', xpath.parse('0.525 div 1000000 div 1000000 div 1000000 div 1000000').evaluateString());
+ assert.equal('525000000000000000000000', xpath.parse('0.525 * 1000000 * 1000000 * 1000000 * 1000000').evaluateString());
+
+ test.done();
+ }
+
+ ,'local-name() and name() of processing instruction': function (test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+ var expectedName = 'book-record';
+ var localName = xpath.select('local-name(/processing-instruction())', doc);
+ var name = xpath.select('name(/processing-instruction())', doc);
+
+ assert.deepEqual(expectedName, localName, 'local-name() - "' + expectedName + '" !== "' + localName + '"');
+ assert.deepEqual(expectedName, name, 'name() - "' + expectedName + '" !== "' + name + '"');
+
+ test.done();
+ },
+
+ 'evaluate substring-after': function (test) {
+ var xml = 'Hermione';
+ var doc = new dom().parseFromString(xml);
+
+ var part = xpath.select('substring-after(/classmate, "Her")', doc);
+ assert.deepEqual('mione', part);
+
+ test.done();
+ }
+
+ ,'parsed expression with no options': function (test) {
+ var parsed = xpath.parse('5 + 7');
+
+ assert.equal(typeof parsed, "object", "parse() should return an object");
+ assert.equal(typeof parsed.evaluate, "function", "parsed.evaluate should be a function");
+ assert.equal(typeof parsed.evaluateNumber, "function", "parsed.evaluateNumber should be a function");
+
+ assert.equal(parsed.evaluateNumber(), 12);
+
+ // evaluating twice should yield the same result
+ assert.equal(parsed.evaluateNumber(), 12);
+
+ test.done();
+ }
+
+ ,'select1() on parsed expression': function (test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+ var parsed = xpath.parse('/*/title');
+
+ assert.equal(typeof parsed, 'object', 'parse() should return an object');
+
+ assert.equal(typeof parsed.select1, 'function', 'parsed.select1 should be a function');
+
+ var single = parsed.select1({ node: doc });
+
+ assert.equal('title', single.localName);
+ assert.equal('Harry Potter', single.firstChild.data);
+ assert.equal('Harry Potter', single.toString());
+
+ test.done();
+ }
+
+ ,'select() on parsed expression': function (test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+ var parsed = xpath.parse('/*/title');
+
+ assert.equal(typeof parsed, 'object', 'parse() should return an object');
+
+ assert.equal(typeof parsed.select, 'function', 'parsed.select should be a function');
+
+ var nodes = parsed.select({ node: doc });
+
+ assert.ok(nodes, 'parsed.select() should return a value');
+ assert.equal(1, nodes.length);
+ assert.equal('title', nodes[0].localName);
+ assert.equal('Harry Potter', nodes[0].firstChild.data);
+ assert.equal('Harry Potter', nodes[0].toString());
+
+ test.done();
+ }
+
+ ,'evaluateString(), and evaluateNumber() on parsed expression with node': function (test) {
+ var xml = 'Harry Potter7';
+ var doc = new dom().parseFromString(xml);
+ var parsed = xpath.parse('/*/numVolumes');
+
+ assert.equal(typeof parsed, 'object', 'parse() should return an object');
+
+ assert.equal(typeof parsed.evaluateString, 'function', 'parsed.evaluateString should be a function');
+ assert.equal('7', parsed.evaluateString({ node: doc }));
+
+ assert.equal(typeof parsed.evaluateBoolean, 'function', 'parsed.evaluateBoolean should be a function');
+ assert.equal(true, parsed.evaluateBoolean({ node: doc }));
+
+ assert.equal(typeof parsed.evaluateNumber, 'function', 'parsed.evaluateNumber should be a function');
+ assert.equal(7, parsed.evaluateNumber({ node: doc }));
+
+ test.done();
+ }
+
+ ,'evaluateBoolean() on parsed empty node set and boolean expressions': function (test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+ var context = { node: doc };
+
+ function evaluate(path) {
+ return xpath.parse(path).evaluateBoolean({ node: doc });
+ }
+
+ assert.equal(false, evaluate('/*/myrtle'), 'boolean value of empty node set should be false');
+
+ assert.equal(true, evaluate('not(/*/myrtle)'), 'not() of empty nodeset should be true');
+
+ assert.equal(true, evaluate('/*/title'), 'boolean value of non-empty nodeset should be true');
+
+ assert.equal(true, evaluate('/*/title = "Harry Potter"'), 'title equals Harry Potter');
+
+ assert.equal(false, evaluate('/*/title != "Harry Potter"'), 'title != Harry Potter should be false');
+
+ assert.equal(false, evaluate('/*/title = "Percy Jackson"'), 'title should not equal Percy Jackson');
+
+ test.done();
+ }
+
+ ,'namespaces with parsed expression': function (test) {
+ var xml = '' +
+ 'QuirrellFluffy' +
+ 'MyrtleTom Riddle' +
+ '';
+ var doc = new dom().parseFromString(xml);
+
+ var expr = xpath.parse('/characters/c:character');
+ var countExpr = xpath.parse('count(/characters/c:character)');
+ var csns = 'http://chamber-secrets.com';
+
+ function resolve(prefix) {
+ if (prefix === 'c') {
+ return csns;
+ }
+ }
+
+ function testContext(context, description) {
+ try {
+ var value = expr.evaluateString(context);
+ var count = countExpr.evaluateNumber(context);
+
+ assert.equal('Myrtle', value, description + ' - string value - ' + value);
+ assert.equal(2, count, description + ' map - count - ' + count);
+ } catch(e) {
+ e.message = description + ': ' + (e.message || '');
+ throw e;
+ }
+ }
+
+ testContext({
+ node: doc,
+ namespaces: {
+ c: csns
+ }
+ }, 'Namespace map');
+
+ testContext({
+ node: doc,
+ namespaces: resolve
+ }, 'Namespace function');
+
+ testContext({
+ node: doc,
+ namespaces: {
+ getNamespace: resolve
+ }
+ }, 'Namespace object');
+
+ test.done();
+ }
+
+ ,'custom functions': function (test) {
+ var xml = 'Harry Potter';
+ var doc = new dom().parseFromString(xml);
+
+ var parsed = xpath.parse('concat(double(/*/title), " is cool")');
+
+ function doubleString(context, value) {
+ assert.equal(2, arguments.length);
+ var str = value.stringValue();
+ return str + str;
+ }
+
+ function functions(name, namespace) {
+ if(name === 'double') {
+ return doubleString;
+ }
+ return null;
+ }
+
+ function testContext(context, description) {
+ try{
+ var actual = parsed.evaluateString(context);
+ var expected = 'Harry PotterHarry Potter is cool';
+ assert.equal(expected, actual, description + ' - ' + expected + ' != ' + actual);
+ } catch (e) {
+ e.message = description + ": " + (e.message || '');
+ throw e;
+ }
+ }
+
+ testContext({
+ node: doc,
+ functions: functions
+ }, 'Functions function');
+
+ testContext({
+ node: doc,
+ functions: {
+ getFunction: functions
+ }
+ }, 'Functions object');
+
+ testContext({
+ node: doc,
+ functions: {
+ double: doubleString
+ }
+ }, 'Functions map');
+
+ test.done();
+ }
+
+ ,'custom function namespaces': function (test) {
+ var xml = 'Harry PotterRonHermioneNeville';
+ var doc = new dom().parseFromString(xml);
+
+ var parsed = xpath.parse('concat(hp:double(/*/title), " is 2 cool ", hp:square(2), " school")');
+ var hpns = 'http://harry-potter.com';
+
+ var namespaces = {
+ hp: hpns
+ };
+
+ var context = {
+ node: doc,
+ namespaces: {
+ hp: hpns
+ },
+ functions: function (name, namespace) {
+ if (namespace === hpns) {
+ switch (name) {
+ case "double":
+ return function (context, value) {
+ assert.equal(2, arguments.length);
+ var str = value.stringValue();
+ return str + str;
+ };
+ case "square":
+ return function (context, value) {
+ var num = value.numberValue();
+ return num * num;
+ };
+
+ case "xor":
+ return function (context, l, r) {
+ assert.equal(3, arguments.length);
+ var lbool = l.booleanValue();
+ var rbool = r.booleanValue();
+ return (lbool || rbool) && !(lbool && rbool);
+ };
+
+ case "second":
+ return function (context, nodes) {
+ var nodesArr = nodes.toArray();
+ var second = nodesArr[1];
+ return second ? [second] : [];
+ };
+ }
+ }
+ return null;
+ }
+ };
+
+ assert.equal('Harry PotterHarry Potter is 2 cool 4 school', parsed.evaluateString(context));
+
+ assert.equal(false, xpath.parse('hp:xor(false(), false())').evaluateBoolean(context));
+ assert.equal(true, xpath.parse('hp:xor(false(), true())').evaluateBoolean(context));
+ assert.equal(true, xpath.parse('hp:xor(true(), false())').evaluateBoolean(context));
+ assert.equal(false, xpath.parse('hp:xor(true(), true())').evaluateBoolean(context));
+
+ assert.equal('Hermione', xpath.parse('hp:second(/*/friend)').evaluateString(context));
+ assert.equal(1, xpath.parse('count(hp:second(/*/friend))').evaluateNumber(context));
+ assert.equal(0, xpath.parse('count(hp:second(/*/friendz))').evaluateNumber(context));
+
+ test.done();
+ }
+
+ ,'xpath variables': function (test) {
+ var xml = 'Harry Potter7';
+ var doc = new dom().parseFromString(xml);
+
+ var variables = {
+ title: 'Harry Potter',
+ notTitle: 'Percy Jackson',
+ houses: 4
+ };
+
+ function variableFunction(name) {
+ return variables[name];
+ }
+
+ function testContext(context, description) {
+ try{
+ assert.equal(true, xpath.parse('$title = /*/title').evaluateBoolean(context));
+ assert.equal(false, xpath.parse('$notTitle = /*/title').evaluateBoolean(context));
+ assert.equal(11, xpath.parse('$houses + /*/volumes').evaluateNumber(context));
+ } catch (e) {
+ e.message = description + ": " + (e.message || '');
+ throw e;
+ }
+ }
+
+ testContext({
+ node: doc,
+ variables: variableFunction
+ }, 'Variables function');
+
+ testContext({
+ node: doc,
+ variables: {
+ getVariable: variableFunction
+ }
+ }, 'Variables object');
+
+ testContext({
+ node: doc,
+ variables: variables
+ }, 'Variables map');
+
+ test.done();
+ }
+
+ ,'xpath variable namespaces': function (test) {
+ var xml = 'Harry Potter7';
+ var doc = new dom().parseFromString(xml);
+ var hpns = 'http://harry-potter.com';
+
+ var context = {
+ node: doc,
+ namespaces: {
+ hp: hpns
+ },
+ variables: function(name, namespace) {
+ if (namespace === hpns) {
+ switch (name) {
+ case 'title': return 'Harry Potter';
+ case 'houses': return 4;
+ case 'false': return false;
+ case 'falseStr': return 'false';
+ }
+ } else if (namespace === '') {
+ switch (name) {
+ case 'title': return 'World';
+ }
+ }
+
+ return null;
+ }
+ };
+
+ assert.equal(true, xpath.parse('$hp:title = /*/title').evaluateBoolean(context));
+ assert.equal(false, xpath.parse('$title = /*/title').evaluateBoolean(context));
+ assert.equal('World', xpath.parse('$title').evaluateString(context));
+ assert.equal(false, xpath.parse('$hp:false').evaluateBoolean(context));
+ assert.notEqual(false, xpath.parse('$hp:falseStr').evaluateBoolean(context));
+ assert.throws(function () {
+ xpath.parse('$hp:hello').evaluateString(context);
+ }, function (err) {
+ return err.message === 'Undeclared variable: $hp:hello';
+ });
+
+ test.done();
+ }
+
+ ,"detect unterminated string literals": function (test) {
+ function testUnterminated(path) {
+ assert.throws(function () {
+ xpath.evaluate('"hello');
+ }, function (err) {
+ return err.message.indexOf('Unterminated') !== -1;
+ });
+ }
+
+ testUnterminated('"Hello');
+ testUnterminated("'Hello");
+ testUnterminated('self::text() = "\""');
+ testUnterminated('"\""');
+
+ test.done();
+ }
+
+ ,"string value for CDATA sections": function (test) {
+ var xml = "Ron ",
+ doc = new dom().parseFromString(xml),
+ person1 = xpath.parse("/people/person").evaluateString({ node: doc }),
+ person2 = xpath.parse("/people/person/text()").evaluateString({ node: doc }),
+ person3 = xpath.select("string(/people/person/text())", doc);
+ person4 = xpath.parse("/people/person[2]").evaluateString({ node: doc });
+
+ assert.equal(person1, 'Harry Potter');
+ assert.equal(person2, 'Harry Potter');
+ assert.equal(person3, 'Harry Potter');
+ assert.equal(person4, 'Ron Weasley');
+
+ test.done();
+ }
+
+ ,"string value of various node types": function (test) {
+ var xml = "Harry Potter",
+ doc = new dom().parseFromString(xml),
+ allText = xpath.parse('.').evaluateString({ node: doc }),
+ ns = xpath.parse('*/namespace::*[name() = "hp"]').evaluateString({ node: doc }),
+ title = xpath.parse('*/title').evaluateString({ node: doc }),
+ child = xpath.parse('*/*').evaluateString({ node: doc }),
+ titleLang = xpath.parse('*/*/@lang').evaluateString({ node: doc }),
+ pi = xpath.parse('*/processing-instruction()').evaluateString({ node: doc }),
+ comment = xpath.parse('*/comment()').evaluateString({ node: doc });
+
+ assert.equal(allText, "Harry Potter & the Philosopher's StoneHarry Potter");
+ assert.equal(ns, 'http://harry');
+ assert.equal(title, "Harry Potter & the Philosopher's Stone");
+ assert.equal(child, "Harry Potter & the Philosopher's Stone");
+ assert.equal(titleLang, 'en');
+ assert.equal(pi.trim(), "name='J.K. Rowling'");
+ assert.equal(comment, ' This describes the Harry Potter Book ');
+
+ test.done();
+ }
+
+ ,"exposes custom types": function (test) {
+ assert.ok(xpath.XPath, "xpath.XPath");
+ assert.ok(xpath.XPathParser, "xpath.XPathParser");
+ assert.ok(xpath.XPathResult, "xpath.XPathResult");
+
+ assert.ok(xpath.Step, "xpath.Step");
+ assert.ok(xpath.NodeTest, "xpath.NodeTest");
+ assert.ok(xpath.BarOperation, "xpath.BarOperation");
+
+ assert.ok(xpath.NamespaceResolver, "xpath.NamespaceResolver");
+ assert.ok(xpath.FunctionResolver, "xpath.FunctionResolver");
+ assert.ok(xpath.VariableResolver, "xpath.VariableResolver");
+
+ assert.ok(xpath.Utilities, "xpath.Utilities");
+
+ assert.ok(xpath.XPathContext, "xpath.XPathContext");
+ assert.ok(xpath.XNodeSet, "xpath.XNodeSet");
+ assert.ok(xpath.XBoolean, "xpath.XBoolean");
+ assert.ok(xpath.XString, "xpath.XString");
+ assert.ok(xpath.XNumber, "xpath.XNumber");
+
+ test.done();
+ }
+
+ ,"work with nodes created using DOM1 createElement()": function (test) {
+ var doc = new dom().parseFromString('');
+
+ doc.documentElement.appendChild(doc.createElement('characters'));
+
+ assert.ok(xpath.select1('/book/characters', doc));
+
+ assert.equal(xpath.select1('local-name(/book/characters)', doc), 'characters');
+
+ test.done();
+ }
+
+ ,"preceding:: axis works on document fragments": function (test) {
+ var doc = new dom().parseFromString(''),
+ df = doc.createDocumentFragment(),
+ root = doc.createElement('book');
+
+ df.appendChild(root);
+
+ for (var i = 0; i < 10; i += 1) {
+ root.appendChild(doc.createElement('chapter'));
+ }
+
+ var chapter = xpath.select1("book/chapter[5]", df);
+
+ assert.ok(chapter, 'chapter');
+
+ assert.equal(xpath.select("count(preceding::chapter)", chapter), 4);
+
+ test.done();
+ }
+
+ ,"node set sorted and unsorted arrays": function (test) {
+ var doc = new dom().parseFromString('HarryRonHermione'),
+ path = xpath.parse("/*/*[3] | /*/*[2] | /*/*[1]")
+ nset = path.evaluateNodeSet({ node: doc }),
+ sorted = nset.toArray(),
+ unsorted = nset.toUnsortedArray();
+
+ assert.equal(sorted.length, 3);
+ assert.equal(unsorted.length, 3);
+
+ assert.equal(sorted[0].textContent, 'Harry');
+ assert.equal(sorted[1].textContent, 'Ron');
+ assert.equal(sorted[2].textContent, 'Hermione');
+
+ assert.notEqual(sorted[0], unsorted[0], "first nodeset element equal");
+
+ test.done();
+ }
+
+ ,'meaningful error for invalid function': function(test) {
+ var path = xpath.parse('invalidFunc()');
+
+ assert.throws(function () {
+ path.evaluateString();
+ }, function (err) {
+ return err.message.indexOf('invalidFunc') !== -1;
+ });
+
+ var path2 = xpath.parse('funcs:invalidFunc()');
+
+ assert.throws(function () {
+ path2.evaluateString({
+ namespaces: {
+ funcs: 'myfunctions'
+ }
+ });
+ }, function (err) {
+ return err.message.indexOf('invalidFunc') !== -1;
+ });
+
+ test.done();
+ }
+
+ // https://github.com/goto100/xpath/issues/32
+ ,'supports contains() function on attributes': function (test) {
+ var doc = new dom().parseFromString(""),
+ andTheBooks = xpath.select("/books/book[contains(@title, ' ')]", doc),
+ secretBooks = xpath.select("/books/book[contains(@title, 'Secrets')]", doc);
+
+ assert.equal(andTheBooks.length, 2);
+ assert.equal(secretBooks.length, 1);
+
+ test.done();
+ }
+
+ ,'compare multiple nodes to multiple nodes (equals)': function (test) {
+ var xml = '' +
+ 'HarryHermione' +
+ 'DracoCrabbe' +
+ 'LunaCho' +
+ '' +
+ 'HermioneLuna';
+
+ var doc = new dom().parseFromString(xml);
+ var houses = xpath.parse('/school/houses/house[student = /school/honorStudents/student]').select({ node: doc });
+
+ assert.equal(houses.length, 2);
+
+ var houseNames = houses.map(function (node) { return node.getAttribute('name'); }).sort();
+
+ assert.equal(houseNames[0], 'Gryffindor');
+ assert.equal(houseNames[1], 'Ravenclaw');
+
+ test.done();
+ }
+
+ ,'compare multiple nodes to multiple nodes (gte)': function (test) {
+ var xml = '' +
+ 'HarryHermione' +
+ 'GoyleCrabbe' +
+ 'LunaCho' +
+ '' +
+ 'DADACharms' +
+ '';
+
+ var doc = new dom().parseFromString(xml);
+ var houses = xpath.parse('/school/houses/house[student/@level >= /school/courses/course/@minLevel]').select({ node: doc });
+
+ assert.equal(houses.length, 2);
+
+ var houseNames = houses.map(function (node) { return node.getAttribute('name'); }).sort();
+
+ assert.equal(houseNames[0], 'Gryffindor');
+ assert.equal(houseNames[1], 'Ravenclaw');
+
+ test.done();
+ }
+
+ ,'inequality comparisons with nodesets': function (test) {
+ var xml = "";
+ var doc = new dom().parseFromString(xml);
+
+ var options = { node: doc, variables: { theNumber: 3, theString: '3', theBoolean: true }};
+
+ var numberPaths = [
+ '/books/book[$theNumber <= @num]',
+ '/books/book[$theNumber < @num]',
+ '/books/book[$theNumber >= @num]',
+ '/books/book[$theNumber > @num]'
+ ];
+
+ var stringPaths = [
+ '/books/book[$theString <= @num]',
+ '/books/book[$theString < @num]',
+ '/books/book[$theString >= @num]',
+ '/books/book[$theString > @num]'
+ ];
+
+ var booleanPaths = [
+ '/books/book[$theBoolean <= @num]',
+ '/books/book[$theBoolean < @num]',
+ '/books/book[$theBoolean >= @num]',
+ '/books/book[$theBoolean > @num]'
+ ];
+
+ var lhsPaths = [
+ '/books/book[@num <= $theNumber]',
+ '/books/book[@num < $theNumber]'
+ ];
+
+ function countNodes(paths){
+ return paths
+ .map(xpath.parse)
+ .map(function (path) { return path.select(options) })
+ .map(function (arr) { return arr.length; });
+ }
+
+ assert.deepEqual(countNodes(numberPaths), [5, 4, 3, 2], 'numbers');
+ assert.deepEqual(countNodes(stringPaths), [5, 4, 3, 2], 'strings');
+ assert.deepEqual(countNodes(booleanPaths), [7, 6, 1, 0], 'numbers');
+ assert.deepEqual(countNodes(lhsPaths), [3, 2], 'lhs');
+
+ test.done();
+ }
+
+ ,'error when evaluating boolean as number': function (test) {
+ var num = xpath.parse('"a" = "b"').evaluateNumber();
+
+ assert.equal(num, 0);
+
+ var str = xpath.select('substring("expelliarmus", 1, "a" = "a")');
+
+ assert.equal(str, 'e');
+
+ test.done();
+ }
+
+ ,'string values of parsed expressions': function (test) {
+ var parser = new xpath.XPathParser();
+
+ var simpleStep = parser.parse('my:book');
+
+ assert.equal(simpleStep.toString(), 'child::my:book');
+
+ var precedingSib = parser.parse('preceding-sibling::my:chapter');
+
+ assert.equal(precedingSib.toString(), 'preceding-sibling::my:chapter');
+
+ var withPredicates = parser.parse('book[number > 3][contains(title, "and the")]');
+
+ assert.equal(withPredicates.toString(), "child::book[(child::number > 3)][contains(child::title, 'and the')]");
+
+ var parenthesisWithPredicate = parser.parse('(/books/book/chapter)[7]');
+
+ assert.equal(parenthesisWithPredicate.toString(), '(/child::books/child::book/child::chapter)[7]');
+
+ var charactersOver20 = parser.parse('heroes[age > 20] | villains[age > 20]');
+
+ assert.equal(charactersOver20.toString(), 'child::heroes[(child::age > 20)] | child::villains[(child::age > 20)]');
+
+ test.done();
+ }
+
+ ,'context position should work correctly': function (test) {
+ var doc = new dom().parseFromString("The boy who livedThe vanishing glassThe worst birthdayDobby's warningThe burrow");
+
+ var chapters = xpath.parse('/books/book/chapter[2]').select({ node: doc });
+
+ assert.equal(2, chapters.length);
+ assert.equal('The vanishing glass', chapters[0].textContent);
+ assert.equal("Dobby's warning", chapters[1].textContent);
+
+ var lastChapters = xpath.parse('/books/book/chapter[last()]').select({ node: doc });
+
+ assert.equal(2, lastChapters.length);
+ assert.equal('The vanishing glass', lastChapters[0].textContent);
+ assert.equal("The burrow", lastChapters[1].textContent);
+
+ var secondChapter = xpath.parse('(/books/book/chapter)[2]').select({ node: doc });
+
+ assert.equal(1, secondChapter.length);
+ assert.equal('The vanishing glass', chapters[0].textContent);
+
+ var lastChapter = xpath.parse('(/books/book/chapter)[last()]').select({ node: doc });
+
+ assert.equal(1, lastChapter.length);
+ assert.equal("The burrow", lastChapter[0].textContent);
+
+
+ test.done();
+ }
+
+ ,'should allow null namespaces for null prefixes': function (test) {
+ var markup = 'Hi Ron!
Hi Draco!
Hi Hermione!
';
+ var docHtml = new dom().parseFromString(markup, 'text/html');
+
+ var noPrefixPath = xpath.parse('/html/body/p[2]');
+
+ var greetings1 = noPrefixPath.select({ node: docHtml, allowAnyNamespaceForNoPrefix: false });
+
+ assert.equal(0, greetings1.length);
+
+ var allowAnyNamespaceOptions = { node: docHtml, allowAnyNamespaceForNoPrefix: true };
+
+ // if allowAnyNamespaceForNoPrefix specified, allow using prefix-less node tests to match nodes with no prefix
+ var greetings2 = noPrefixPath.select(allowAnyNamespaceOptions);
+
+ assert.equal(1, greetings2.length);
+ assert.equal('Hi Hermione!', greetings2[0].textContent);
+
+ var allGreetings = xpath.parse('/html/body/p').select(allowAnyNamespaceOptions);
+
+ assert.equal(2, allGreetings.length);
+
+ var nsm = { html: xhtmlNs, other: 'http://www.example.com/other' };
+
+ var prefixPath = xpath.parse('/html:html/body/html:p');
+ var optionsWithNamespaces = { node: docHtml, allowAnyNamespaceForNoPrefix: true, namespaces: nsm };
+
+ // if the path uses prefixes, they have to match
+ var greetings3 = prefixPath.select(optionsWithNamespaces);
+
+ assert.equal(2, greetings3.length);
+
+ var badPrefixPath = xpath.parse('/html:html/other:body/html:p');
+
+ var greetings4 = badPrefixPath.select(optionsWithNamespaces);
+
+ test.done();
+ }
+
+ ,'support isHtml option' : function (test){
+ var markup = 'Hi Ron!
Hi Draco!Hi Hermione!
';
+ var docHtml = new dom().parseFromString(markup, 'text/html');
+
+ var ns = { h: xhtmlNs };
+
+ // allow matching on unprefixed nodes
+ var greetings1 = xpath.parse('/html/body/p').select({ node: docHtml, isHtml: true });
+
+ assert.equal(2, greetings1.length);
+
+ // allow case insensitive match
+ var greetings2 = xpath.parse('/h:html/h:bOdY/h:p').select({ node: docHtml, namespaces: ns, isHtml: true });
+
+ assert.equal(2, greetings2.length);
+
+ // non-html mode: allow select if case and namespaces match
+ var greetings3 = xpath.parse('/h:html/h:body/h:p').select({ node: docHtml, namespaces: ns });
+
+ assert.equal(2, greetings3.length);
+
+ // non-html mode: require namespaces
+ var greetings4 = xpath.parse('/html/body/p').select({ node: docHtml, namespaces: ns });
+
+ assert.equal(0, greetings4.length);
+
+ // non-html mode: require case to match
+ var greetings5 = xpath.parse('/h:html/h:bOdY/h:p').select({ node: docHtml, namespaces: ns });
+
+ assert.equal(0, greetings5.length);
+
+ test.done();
+ }
+
+ ,"builtin functions": function (test) {
+ var translated = xpath.parse('translate("hello", "lhho", "yHb")').evaluateString();
+
+ assert.equal('Heyy', translated);
+
+ var characters = new dom().parseFromString('HarryRonHermione');
+
+ var firstTwo = xpath.parse('/characters/character[position() <= 2]').select({ node: characters });
+
+ assert.equal(2, firstTwo.length);
+ assert.equal('Harry', firstTwo[0].textContent);
+ assert.equal('Ron', firstTwo[1].textContent);
+
+ var last = xpath.parse('/characters/character[last()]').select({ node: characters });
+
+ assert.equal(1, last.length);
+ assert.equal('Hermione', last[0].textContent);
+
+ test.done();
+ }
+}
diff --git a/node_modules/xpath/xpath.d.ts b/node_modules/xpath/xpath.d.ts
new file mode 100644
index 00000000..ac95996d
--- /dev/null
+++ b/node_modules/xpath/xpath.d.ts
@@ -0,0 +1,9 @@
+type SelectedValue = Node | Attr | string | number | boolean;
+interface XPathSelect {
+ (expression: string, node?: Node): Array;
+ (expression: string, node: Node, single: true): SelectedValue;
+}
+export var select: XPathSelect;
+export function select1(expression: string, node?: Node): SelectedValue;
+export function evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver, type: number, result: XPathResult): XPathResult;
+export function useNamespaces(namespaceMap: { [name: string]: string }): XPathSelect;
diff --git a/node_modules/xpath/xpath.js b/node_modules/xpath/xpath.js
new file mode 100644
index 00000000..02732c02
--- /dev/null
+++ b/node_modules/xpath/xpath.js
@@ -0,0 +1,4764 @@
+/*
+ * xpath.js
+ *
+ * An XPath 1.0 library for JavaScript.
+ *
+ * Cameron McCormack
+ *
+ * This work is licensed under the MIT License.
+ *
+ * Revision 20: April 26, 2011
+ * Fixed a typo resulting in FIRST_ORDERED_NODE_TYPE results being wrong,
+ * thanks to .
+ *
+ * Revision 19: November 29, 2005
+ * Nodesets now store their nodes in a height balanced tree, increasing
+ * performance for the common case of selecting nodes in document order,
+ * thanks to S閎astien Cramatte .
+ * AVL tree code adapted from Raimund Neumann .
+ *
+ * Revision 18: October 27, 2005
+ * DOM 3 XPath support. Caveats:
+ * - namespace prefixes aren't resolved in XPathEvaluator.createExpression,
+ * but in XPathExpression.evaluate.
+ * - XPathResult.invalidIteratorState is not implemented.
+ *
+ * Revision 17: October 25, 2005
+ * Some core XPath function fixes and a patch to avoid crashing certain
+ * versions of MSXML in PathExpr.prototype.getOwnerElement, thanks to
+ * S閎astien Cramatte .
+ *
+ * Revision 16: September 22, 2005
+ * Workarounds for some IE 5.5 deficiencies.
+ * Fixed problem with prefix node tests on attribute nodes.
+ *
+ * Revision 15: May 21, 2005
+ * Fixed problem with QName node tests on elements with an xmlns="...".
+ *
+ * Revision 14: May 19, 2005
+ * Fixed QName node tests on attribute node regression.
+ *
+ * Revision 13: May 3, 2005
+ * Node tests are case insensitive now if working in an HTML DOM.
+ *
+ * Revision 12: April 26, 2005
+ * Updated licence. Slight code changes to enable use of Dean
+ * Edwards' script compression, http://dean.edwards.name/packer/ .
+ *
+ * Revision 11: April 23, 2005
+ * Fixed bug with 'and' and 'or' operators, fix thanks to
+ * Sandy McArthur .
+ *
+ * Revision 10: April 15, 2005
+ * Added support for a virtual root node, supposedly helpful for
+ * implementing XForms. Fixed problem with QName node tests and
+ * the parent axis.
+ *
+ * Revision 9: March 17, 2005
+ * Namespace resolver tweaked so using the document node as the context
+ * for namespace lookups is equivalent to using the document element.
+ *
+ * Revision 8: February 13, 2005
+ * Handle implicit declaration of 'xmlns' namespace prefix.
+ * Fixed bug when comparing nodesets.
+ * Instance data can now be associated with a FunctionResolver, and
+ * workaround for MSXML not supporting 'localName' and 'getElementById',
+ * thanks to Grant Gongaware.
+ * Fix a few problems when the context node is the root node.
+ *
+ * Revision 7: February 11, 2005
+ * Default namespace resolver fix from Grant Gongaware
+ * .
+ *
+ * Revision 6: February 10, 2005
+ * Fixed bug in 'number' function.
+ *
+ * Revision 5: February 9, 2005
+ * Fixed bug where text nodes not getting converted to string values.
+ *
+ * Revision 4: January 21, 2005
+ * Bug in 'name' function, fix thanks to Bill Edney.
+ * Fixed incorrect processing of namespace nodes.
+ * Fixed NamespaceResolver to resolve 'xml' namespace.
+ * Implemented union '|' operator.
+ *
+ * Revision 3: January 14, 2005
+ * Fixed bug with nodeset comparisons, bug lexing < and >.
+ *
+ * Revision 2: October 26, 2004
+ * QName node test namespace handling fixed. Few other bug fixes.
+ *
+ * Revision 1: August 13, 2004
+ * Bug fixes from William J. Edney .
+ * Added minimal licence.
+ *
+ * Initial version: June 14, 2004
+ */
+
+// non-node wrapper
+var xpath = (typeof exports === 'undefined') ? {} : exports;
+
+(function(exports) {
+"use strict";
+
+// functional helpers
+function curry( func ) {
+ var slice = Array.prototype.slice,
+ totalargs = func.length,
+ partial = function( args, fn ) {
+ return function( ) {
+ return fn.apply( this, args.concat( slice.call( arguments ) ) );
+ }
+ },
+ fn = function( ) {
+ var args = slice.call( arguments );
+ return ( args.length < totalargs ) ?
+ partial( args, fn ) :
+ func.apply( this, slice.apply( arguments, [ 0, totalargs ] ) );
+ };
+ return fn;
+}
+
+var forEach = curry(function (f, xs) {
+ for (var i = 0; i < xs.length; i += 1) {
+ f(xs[i], i, xs);
+ }
+});
+
+var reduce = curry(function (f, seed, xs) {
+ var acc = seed;
+
+ forEach(function (x, i) { acc = f(acc, x, i); }, xs);
+
+ return acc;
+});
+
+var map = curry(function (f, xs) {
+ var mapped = new Array(xs.length);
+
+ forEach(function (x, i) { mapped[i] = f(x); }, xs);
+
+ return mapped;
+});
+
+var filter = curry(function (f, xs) {
+ var filtered = [];
+
+ forEach(function (x, i) { if(f(x, i)) { filtered.push(x); } }, xs);
+
+ return filtered;
+});
+
+function compose() {
+ if (arguments.length === 0) { throw new Error('compose requires at least one argument'); }
+
+ var funcs = Array.prototype.slice.call(arguments).reverse();
+
+ var f0 = funcs[0];
+ var fRem = funcs.slice(1);
+
+ return function () {
+ return reduce(function (acc, next) {
+ return next(acc);
+ }, f0.apply(null, arguments), fRem);
+ };
+}
+
+var includes = curry(function (values, value) {
+ for (var i = 0; i < values.length; i += 1) {
+ if (values[i] === value){
+ return true;
+ }
+ }
+
+ return false;
+});
+
+function always(value) { return function () { return value ;} }
+
+var prop = curry(function (name, obj) { return obj[name]; });
+
+function toString (x) { return x.toString(); }
+var join = curry(function (s, xs) { return xs.join(s); });
+var wrap = curry(function (pref, suf, str) { return pref + str + suf; });
+
+function assign(target) { // .length of function is 2
+ var to = Object(target);
+
+ for (var index = 1; index < arguments.length; index++) {
+ var nextSource = arguments[index];
+
+ if (nextSource != null) { // Skip over if undefined or null
+ for (var nextKey in nextSource) {
+ // Avoid bugs when hasOwnProperty is shadowed
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
+ to[nextKey] = nextSource[nextKey];
+ }
+ }
+ }
+ }
+
+ return to;
+}
+
+// XPathParser ///////////////////////////////////////////////////////////////
+
+XPathParser.prototype = new Object();
+XPathParser.prototype.constructor = XPathParser;
+XPathParser.superclass = Object.prototype;
+
+function XPathParser() {
+ this.init();
+}
+
+XPathParser.prototype.init = function() {
+ this.reduceActions = [];
+
+ this.reduceActions[3] = function(rhs) {
+ return new OrOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[5] = function(rhs) {
+ return new AndOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[7] = function(rhs) {
+ return new EqualsOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[8] = function(rhs) {
+ return new NotEqualOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[10] = function(rhs) {
+ return new LessThanOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[11] = function(rhs) {
+ return new GreaterThanOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[12] = function(rhs) {
+ return new LessThanOrEqualOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[13] = function(rhs) {
+ return new GreaterThanOrEqualOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[15] = function(rhs) {
+ return new PlusOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[16] = function(rhs) {
+ return new MinusOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[18] = function(rhs) {
+ return new MultiplyOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[19] = function(rhs) {
+ return new DivOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[20] = function(rhs) {
+ return new ModOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[22] = function(rhs) {
+ return new UnaryMinusOperation(rhs[1]);
+ };
+ this.reduceActions[24] = function(rhs) {
+ return new BarOperation(rhs[0], rhs[2]);
+ };
+ this.reduceActions[25] = function(rhs) {
+ return new PathExpr(undefined, undefined, rhs[0]);
+ };
+ this.reduceActions[27] = function(rhs) {
+ rhs[0].locationPath = rhs[2];
+ return rhs[0];
+ };
+ this.reduceActions[28] = function(rhs) {
+ rhs[0].locationPath = rhs[2];
+ rhs[0].locationPath.steps.unshift(new Step(Step.DESCENDANTORSELF, NodeTest.nodeTest, []));
+ return rhs[0];
+ };
+ this.reduceActions[29] = function(rhs) {
+ return new PathExpr(rhs[0], [], undefined);
+ };
+ this.reduceActions[30] = function(rhs) {
+ if (Utilities.instance_of(rhs[0], PathExpr)) {
+ if (rhs[0].filterPredicates == undefined) {
+ rhs[0].filterPredicates = [];
+ }
+ rhs[0].filterPredicates.push(rhs[1]);
+ return rhs[0];
+ } else {
+ return new PathExpr(rhs[0], [rhs[1]], undefined);
+ }
+ };
+ this.reduceActions[32] = function(rhs) {
+ return rhs[1];
+ };
+ this.reduceActions[33] = function(rhs) {
+ return new XString(rhs[0]);
+ };
+ this.reduceActions[34] = function(rhs) {
+ return new XNumber(rhs[0]);
+ };
+ this.reduceActions[36] = function(rhs) {
+ return new FunctionCall(rhs[0], []);
+ };
+ this.reduceActions[37] = function(rhs) {
+ return new FunctionCall(rhs[0], rhs[2]);
+ };
+ this.reduceActions[38] = function(rhs) {
+ return [ rhs[0] ];
+ };
+ this.reduceActions[39] = function(rhs) {
+ rhs[2].unshift(rhs[0]);
+ return rhs[2];
+ };
+ this.reduceActions[43] = function(rhs) {
+ return new LocationPath(true, []);
+ };
+ this.reduceActions[44] = function(rhs) {
+ rhs[1].absolute = true;
+ return rhs[1];
+ };
+ this.reduceActions[46] = function(rhs) {
+ return new LocationPath(false, [ rhs[0] ]);
+ };
+ this.reduceActions[47] = function(rhs) {
+ rhs[0].steps.push(rhs[2]);
+ return rhs[0];
+ };
+ this.reduceActions[49] = function(rhs) {
+ return new Step(rhs[0], rhs[1], []);
+ };
+ this.reduceActions[50] = function(rhs) {
+ return new Step(Step.CHILD, rhs[0], []);
+ };
+ this.reduceActions[51] = function(rhs) {
+ return new Step(rhs[0], rhs[1], rhs[2]);
+ };
+ this.reduceActions[52] = function(rhs) {
+ return new Step(Step.CHILD, rhs[0], rhs[1]);
+ };
+ this.reduceActions[54] = function(rhs) {
+ return [ rhs[0] ];
+ };
+ this.reduceActions[55] = function(rhs) {
+ rhs[1].unshift(rhs[0]);
+ return rhs[1];
+ };
+ this.reduceActions[56] = function(rhs) {
+ if (rhs[0] == "ancestor") {
+ return Step.ANCESTOR;
+ } else if (rhs[0] == "ancestor-or-self") {
+ return Step.ANCESTORORSELF;
+ } else if (rhs[0] == "attribute") {
+ return Step.ATTRIBUTE;
+ } else if (rhs[0] == "child") {
+ return Step.CHILD;
+ } else if (rhs[0] == "descendant") {
+ return Step.DESCENDANT;
+ } else if (rhs[0] == "descendant-or-self") {
+ return Step.DESCENDANTORSELF;
+ } else if (rhs[0] == "following") {
+ return Step.FOLLOWING;
+ } else if (rhs[0] == "following-sibling") {
+ return Step.FOLLOWINGSIBLING;
+ } else if (rhs[0] == "namespace") {
+ return Step.NAMESPACE;
+ } else if (rhs[0] == "parent") {
+ return Step.PARENT;
+ } else if (rhs[0] == "preceding") {
+ return Step.PRECEDING;
+ } else if (rhs[0] == "preceding-sibling") {
+ return Step.PRECEDINGSIBLING;
+ } else if (rhs[0] == "self") {
+ return Step.SELF;
+ }
+ return -1;
+ };
+ this.reduceActions[57] = function(rhs) {
+ return Step.ATTRIBUTE;
+ };
+ this.reduceActions[59] = function(rhs) {
+ if (rhs[0] == "comment") {
+ return NodeTest.commentTest;
+ } else if (rhs[0] == "text") {
+ return NodeTest.textTest;
+ } else if (rhs[0] == "processing-instruction") {
+ return NodeTest.anyPiTest;
+ } else if (rhs[0] == "node") {
+ return NodeTest.nodeTest;
+ }
+ return new NodeTest(-1, undefined);
+ };
+ this.reduceActions[60] = function(rhs) {
+ return new NodeTest.PITest(rhs[2]);
+ };
+ this.reduceActions[61] = function(rhs) {
+ return rhs[1];
+ };
+ this.reduceActions[63] = function(rhs) {
+ rhs[1].absolute = true;
+ rhs[1].steps.unshift(new Step(Step.DESCENDANTORSELF, NodeTest.nodeTest, []));
+ return rhs[1];
+ };
+ this.reduceActions[64] = function(rhs) {
+ rhs[0].steps.push(new Step(Step.DESCENDANTORSELF, NodeTest.nodeTest, []));
+ rhs[0].steps.push(rhs[2]);
+ return rhs[0];
+ };
+ this.reduceActions[65] = function(rhs) {
+ return new Step(Step.SELF, NodeTest.nodeTest, []);
+ };
+ this.reduceActions[66] = function(rhs) {
+ return new Step(Step.PARENT, NodeTest.nodeTest, []);
+ };
+ this.reduceActions[67] = function(rhs) {
+ return new VariableReference(rhs[1]);
+ };
+ this.reduceActions[68] = function(rhs) {
+ return NodeTest.nameTestAny;
+ };
+ this.reduceActions[69] = function(rhs) {
+ return new NodeTest.NameTestPrefixAny(rhs[0].split(':')[0]);
+ };
+ this.reduceActions[70] = function(rhs) {
+ return new NodeTest.NameTestQName(rhs[0]);
+ };
+};
+
+XPathParser.actionTable = [
+ " s s sssssssss s ss s ss",
+ " s ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ " rrrrr ",
+ " s s sssssssss s ss s ss",
+ "rs rrrrrrrr s sssssrrrrrr rrs rs ",
+ " s s sssssssss s ss s ss",
+ " s ",
+ " s ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " s ",
+ " s ",
+ " s s sssss s s ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "a ",
+ "r s rr r ",
+ "r sr rr r ",
+ "r s rr s rr r ",
+ "r rssrr rss rr r ",
+ "r rrrrr rrrss rr r ",
+ "r rrrrrsss rrrrr rr r ",
+ "r rrrrrrrr rrrrr rr r ",
+ "r rrrrrrrr rrrrrs rr r ",
+ "r rrrrrrrr rrrrrr rr r ",
+ "r rrrrrrrr rrrrrr rr r ",
+ "r srrrrrrrr rrrrrrs rr sr ",
+ "r srrrrrrrr rrrrrrs rr r ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrr rrrrrr rr r ",
+ "r rrrrrrrr rrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ " sssss ",
+ "r rrrrrrrrr rrrrrrr rr sr ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " s ",
+ "r srrrrrrrr rrrrrrs rr r ",
+ "r rrrrrrrr rrrrr rr r ",
+ " s ",
+ " s ",
+ " rrrrr ",
+ " s s sssssssss s sss s ss",
+ "r srrrrrrrr rrrrrrs rr r ",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssssssss ss s ss",
+ " s s sssssssss s ss s ss",
+ " s s sssss s s ",
+ " s s sssss s s ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " s s sssss s s ",
+ " s s sssss s s ",
+ "r rrrrrrrrr rrrrrrr rr sr ",
+ "r rrrrrrrrr rrrrrrr rr sr ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " s ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " rr ",
+ " s ",
+ " rs ",
+ "r sr rr r ",
+ "r s rr s rr r ",
+ "r rssrr rss rr r ",
+ "r rssrr rss rr r ",
+ "r rrrrr rrrss rr r ",
+ "r rrrrr rrrss rr r ",
+ "r rrrrr rrrss rr r ",
+ "r rrrrr rrrss rr r ",
+ "r rrrrrsss rrrrr rr r ",
+ "r rrrrrsss rrrrr rr r ",
+ "r rrrrrrrr rrrrr rr r ",
+ "r rrrrrrrr rrrrr rr r ",
+ "r rrrrrrrr rrrrr rr r ",
+ "r rrrrrrrr rrrrrr rr r ",
+ " r ",
+ " s ",
+ "r srrrrrrrr rrrrrrs rr r ",
+ "r srrrrrrrr rrrrrrs rr r ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr r ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " s s sssssssss s ss s ss",
+ "r rrrrrrrrr rrrrrrr rr rr ",
+ " r "
+];
+
+XPathParser.actionTableNumber = [
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " J ",
+ "a aaaaaaaaa aaaaaaa aa a ",
+ " YYYYY ",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ "K1 KKKKKKKK . +*)('KKKKKK KK# K\" ",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " N ",
+ " O ",
+ "e eeeeeeeee eeeeeee ee ee ",
+ "f fffffffff fffffff ff ff ",
+ "d ddddddddd ddddddd dd dd ",
+ "B BBBBBBBBB BBBBBBB BB BB ",
+ "A AAAAAAAAA AAAAAAA AA AA ",
+ " P ",
+ " Q ",
+ " 1 . +*)(' # \" ",
+ "b bbbbbbbbb bbbbbbb bb b ",
+ " ",
+ "! S !! ! ",
+ "\" T\" \"\" \" ",
+ "$ V $$ U $$ $ ",
+ "& &ZY&& &XW && & ",
+ ") ))))) )))\\[ )) ) ",
+ ". ....._^] ..... .. . ",
+ "1 11111111 11111 11 1 ",
+ "5 55555555 55555` 55 5 ",
+ "7 77777777 777777 77 7 ",
+ "9 99999999 999999 99 9 ",
+ ": c:::::::: ::::::b :: a: ",
+ "I fIIIIIIII IIIIIIe II I ",
+ "= ========= ======= == == ",
+ "? ????????? ??????? ?? ?? ",
+ "C CCCCCCCCC CCCCCCC CC CC ",
+ "J JJJJJJJJ JJJJJJ JJ J ",
+ "M MMMMMMMM MMMMMM MM M ",
+ "N NNNNNNNNN NNNNNNN NN N ",
+ "P PPPPPPPPP PPPPPPP PP P ",
+ " +*)(' ",
+ "R RRRRRRRRR RRRRRRR RR aR ",
+ "U UUUUUUUUU UUUUUUU UU U ",
+ "Z ZZZZZZZZZ ZZZZZZZ ZZ ZZ ",
+ "c ccccccccc ccccccc cc cc ",
+ " j ",
+ "L fLLLLLLLL LLLLLLe LL L ",
+ "6 66666666 66666 66 6 ",
+ " k ",
+ " l ",
+ " XXXXX ",
+ " 1 0 /.-,+*)(' & %$m # \"!",
+ "_ f________ ______e __ _ ",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 0 /.-,+*)(' %$ # \"!",
+ " 1 0 /.-,+*)(' & %$ # \"!",
+ " 1 . +*)(' # \" ",
+ " 1 . +*)(' # \" ",
+ "> >>>>>>>>> >>>>>>> >> >> ",
+ " 1 . +*)(' # \" ",
+ " 1 . +*)(' # \" ",
+ "Q QQQQQQQQQ QQQQQQQ QQ aQ ",
+ "V VVVVVVVVV VVVVVVV VV aV ",
+ "T TTTTTTTTT TTTTTTT TT T ",
+ "@ @@@@@@@@@ @@@@@@@ @@ @@ ",
+ " \x87 ",
+ "[ [[[[[[[[[ [[[[[[[ [[ [[ ",
+ "D DDDDDDDDD DDDDDDD DD DD ",
+ " HH ",
+ " \x88 ",
+ " F\x89 ",
+ "# T# ## # ",
+ "% V %% U %% % ",
+ "' 'ZY'' 'XW '' ' ",
+ "( (ZY(( (XW (( ( ",
+ "+ +++++ +++\\[ ++ + ",
+ "* ***** ***\\[ ** * ",
+ "- ----- ---\\[ -- - ",
+ ", ,,,,, ,,,\\[ ,, , ",
+ "0 00000_^] 00000 00 0 ",
+ "/ /////_^] ///// // / ",
+ "2 22222222 22222 22 2 ",
+ "3 33333333 33333 33 3 ",
+ "4 44444444 44444 44 4 ",
+ "8 88888888 888888 88 8 ",
+ " ^ ",
+ " \x8a ",
+ "; f;;;;;;;; ;;;;;;e ;; ; ",
+ "< f<<<<<<<< <<<<<?@ AB CDEFGH IJ ",
+ " ",
+ " ",
+ " ",
+ "L456789:;<=>?@ AB CDEFGH IJ ",
+ " M EFGH IJ ",
+ " N;<=>?@ AB CDEFGH IJ ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " S EFGH IJ ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " e ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " h J ",
+ " i j ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ "o456789:;<=>?@ ABpqCDEFGH IJ ",
+ " ",
+ " r6789:;<=>?@ AB CDEFGH IJ ",
+ " s789:;<=>?@ AB CDEFGH IJ ",
+ " t89:;<=>?@ AB CDEFGH IJ ",
+ " u89:;<=>?@ AB CDEFGH IJ ",
+ " v9:;<=>?@ AB CDEFGH IJ ",
+ " w9:;<=>?@ AB CDEFGH IJ ",
+ " x9:;<=>?@ AB CDEFGH IJ ",
+ " y9:;<=>?@ AB CDEFGH IJ ",
+ " z:;<=>?@ AB CDEFGH IJ ",
+ " {:;<=>?@ AB CDEFGH IJ ",
+ " |;<=>?@ AB CDEFGH IJ ",
+ " };<=>?@ AB CDEFGH IJ ",
+ " ~;<=>?@ AB CDEFGH IJ ",
+ " \x7f=>?@ AB CDEFGH IJ ",
+ "\x80456789:;<=>?@ AB CDEFGH IJ\x81",
+ " \x82 EFGH IJ ",
+ " \x83 EFGH IJ ",
+ " ",
+ " \x84 GH IJ ",
+ " \x85 GH IJ ",
+ " i \x86 ",
+ " i \x87 ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ "o456789:;<=>?@ AB\x8cqCDEFGH IJ ",
+ " ",
+ " "
+];
+
+XPathParser.productions = [
+ [1, 1, 2],
+ [2, 1, 3],
+ [3, 1, 4],
+ [3, 3, 3, -9, 4],
+ [4, 1, 5],
+ [4, 3, 4, -8, 5],
+ [5, 1, 6],
+ [5, 3, 5, -22, 6],
+ [5, 3, 5, -5, 6],
+ [6, 1, 7],
+ [6, 3, 6, -23, 7],
+ [6, 3, 6, -24, 7],
+ [6, 3, 6, -6, 7],
+ [6, 3, 6, -7, 7],
+ [7, 1, 8],
+ [7, 3, 7, -25, 8],
+ [7, 3, 7, -26, 8],
+ [8, 1, 9],
+ [8, 3, 8, -12, 9],
+ [8, 3, 8, -11, 9],
+ [8, 3, 8, -10, 9],
+ [9, 1, 10],
+ [9, 2, -26, 9],
+ [10, 1, 11],
+ [10, 3, 10, -27, 11],
+ [11, 1, 12],
+ [11, 1, 13],
+ [11, 3, 13, -28, 14],
+ [11, 3, 13, -4, 14],
+ [13, 1, 15],
+ [13, 2, 13, 16],
+ [15, 1, 17],
+ [15, 3, -29, 2, -30],
+ [15, 1, -15],
+ [15, 1, -16],
+ [15, 1, 18],
+ [18, 3, -13, -29, -30],
+ [18, 4, -13, -29, 19, -30],
+ [19, 1, 20],
+ [19, 3, 20, -31, 19],
+ [20, 1, 2],
+ [12, 1, 14],
+ [12, 1, 21],
+ [21, 1, -28],
+ [21, 2, -28, 14],
+ [21, 1, 22],
+ [14, 1, 23],
+ [14, 3, 14, -28, 23],
+ [14, 1, 24],
+ [23, 2, 25, 26],
+ [23, 1, 26],
+ [23, 3, 25, 26, 27],
+ [23, 2, 26, 27],
+ [23, 1, 28],
+ [27, 1, 16],
+ [27, 2, 16, 27],
+ [25, 2, -14, -3],
+ [25, 1, -32],
+ [26, 1, 29],
+ [26, 3, -20, -29, -30],
+ [26, 4, -21, -29, -15, -30],
+ [16, 3, -33, 30, -34],
+ [30, 1, 2],
+ [22, 2, -4, 14],
+ [24, 3, 14, -4, 23],
+ [28, 1, -35],
+ [28, 1, -2],
+ [17, 2, -36, -18],
+ [29, 1, -17],
+ [29, 1, -19],
+ [29, 1, -18]
+];
+
+XPathParser.DOUBLEDOT = 2;
+XPathParser.DOUBLECOLON = 3;
+XPathParser.DOUBLESLASH = 4;
+XPathParser.NOTEQUAL = 5;
+XPathParser.LESSTHANOREQUAL = 6;
+XPathParser.GREATERTHANOREQUAL = 7;
+XPathParser.AND = 8;
+XPathParser.OR = 9;
+XPathParser.MOD = 10;
+XPathParser.DIV = 11;
+XPathParser.MULTIPLYOPERATOR = 12;
+XPathParser.FUNCTIONNAME = 13;
+XPathParser.AXISNAME = 14;
+XPathParser.LITERAL = 15;
+XPathParser.NUMBER = 16;
+XPathParser.ASTERISKNAMETEST = 17;
+XPathParser.QNAME = 18;
+XPathParser.NCNAMECOLONASTERISK = 19;
+XPathParser.NODETYPE = 20;
+XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL = 21;
+XPathParser.EQUALS = 22;
+XPathParser.LESSTHAN = 23;
+XPathParser.GREATERTHAN = 24;
+XPathParser.PLUS = 25;
+XPathParser.MINUS = 26;
+XPathParser.BAR = 27;
+XPathParser.SLASH = 28;
+XPathParser.LEFTPARENTHESIS = 29;
+XPathParser.RIGHTPARENTHESIS = 30;
+XPathParser.COMMA = 31;
+XPathParser.AT = 32;
+XPathParser.LEFTBRACKET = 33;
+XPathParser.RIGHTBRACKET = 34;
+XPathParser.DOT = 35;
+XPathParser.DOLLAR = 36;
+
+XPathParser.prototype.tokenize = function(s1) {
+ var types = [];
+ var values = [];
+ var s = s1 + '\0';
+
+ var pos = 0;
+ var c = s.charAt(pos++);
+ while (1) {
+ while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
+ c = s.charAt(pos++);
+ }
+ if (c == '\0' || pos >= s.length) {
+ break;
+ }
+
+ if (c == '(') {
+ types.push(XPathParser.LEFTPARENTHESIS);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == ')') {
+ types.push(XPathParser.RIGHTPARENTHESIS);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '[') {
+ types.push(XPathParser.LEFTBRACKET);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == ']') {
+ types.push(XPathParser.RIGHTBRACKET);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '@') {
+ types.push(XPathParser.AT);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == ',') {
+ types.push(XPathParser.COMMA);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '|') {
+ types.push(XPathParser.BAR);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '+') {
+ types.push(XPathParser.PLUS);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '-') {
+ types.push(XPathParser.MINUS);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '=') {
+ types.push(XPathParser.EQUALS);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c == '$') {
+ types.push(XPathParser.DOLLAR);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+
+ if (c == '.') {
+ c = s.charAt(pos++);
+ if (c == '.') {
+ types.push(XPathParser.DOUBLEDOT);
+ values.push("..");
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (c >= '0' && c <= '9') {
+ var number = "." + c;
+ c = s.charAt(pos++);
+ while (c >= '0' && c <= '9') {
+ number += c;
+ c = s.charAt(pos++);
+ }
+ types.push(XPathParser.NUMBER);
+ values.push(number);
+ continue;
+ }
+ types.push(XPathParser.DOT);
+ values.push('.');
+ continue;
+ }
+
+ if (c == '\'' || c == '"') {
+ var delimiter = c;
+ var literal = "";
+ while (pos < s.length && (c = s.charAt(pos)) !== delimiter) {
+ literal += c;
+ pos += 1;
+ }
+ if (c !== delimiter) {
+ throw XPathException.fromMessage("Unterminated string literal: " + delimiter + literal);
+ }
+ pos += 1;
+ types.push(XPathParser.LITERAL);
+ values.push(literal);
+ c = s.charAt(pos++);
+ continue;
+ }
+
+ if (c >= '0' && c <= '9') {
+ var number = c;
+ c = s.charAt(pos++);
+ while (c >= '0' && c <= '9') {
+ number += c;
+ c = s.charAt(pos++);
+ }
+ if (c == '.') {
+ if (s.charAt(pos) >= '0' && s.charAt(pos) <= '9') {
+ number += c;
+ number += s.charAt(pos++);
+ c = s.charAt(pos++);
+ while (c >= '0' && c <= '9') {
+ number += c;
+ c = s.charAt(pos++);
+ }
+ }
+ }
+ types.push(XPathParser.NUMBER);
+ values.push(number);
+ continue;
+ }
+
+ if (c == '*') {
+ if (types.length > 0) {
+ var last = types[types.length - 1];
+ if (last != XPathParser.AT
+ && last != XPathParser.DOUBLECOLON
+ && last != XPathParser.LEFTPARENTHESIS
+ && last != XPathParser.LEFTBRACKET
+ && last != XPathParser.AND
+ && last != XPathParser.OR
+ && last != XPathParser.MOD
+ && last != XPathParser.DIV
+ && last != XPathParser.MULTIPLYOPERATOR
+ && last != XPathParser.SLASH
+ && last != XPathParser.DOUBLESLASH
+ && last != XPathParser.BAR
+ && last != XPathParser.PLUS
+ && last != XPathParser.MINUS
+ && last != XPathParser.EQUALS
+ && last != XPathParser.NOTEQUAL
+ && last != XPathParser.LESSTHAN
+ && last != XPathParser.LESSTHANOREQUAL
+ && last != XPathParser.GREATERTHAN
+ && last != XPathParser.GREATERTHANOREQUAL) {
+ types.push(XPathParser.MULTIPLYOPERATOR);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+ }
+ types.push(XPathParser.ASTERISKNAMETEST);
+ values.push(c);
+ c = s.charAt(pos++);
+ continue;
+ }
+
+ if (c == ':') {
+ if (s.charAt(pos) == ':') {
+ types.push(XPathParser.DOUBLECOLON);
+ values.push("::");
+ pos++;
+ c = s.charAt(pos++);
+ continue;
+ }
+ }
+
+ if (c == '/') {
+ c = s.charAt(pos++);
+ if (c == '/') {
+ types.push(XPathParser.DOUBLESLASH);
+ values.push("//");
+ c = s.charAt(pos++);
+ continue;
+ }
+ types.push(XPathParser.SLASH);
+ values.push('/');
+ continue;
+ }
+
+ if (c == '!') {
+ if (s.charAt(pos) == '=') {
+ types.push(XPathParser.NOTEQUAL);
+ values.push("!=");
+ pos++;
+ c = s.charAt(pos++);
+ continue;
+ }
+ }
+
+ if (c == '<') {
+ if (s.charAt(pos) == '=') {
+ types.push(XPathParser.LESSTHANOREQUAL);
+ values.push("<=");
+ pos++;
+ c = s.charAt(pos++);
+ continue;
+ }
+ types.push(XPathParser.LESSTHAN);
+ values.push('<');
+ c = s.charAt(pos++);
+ continue;
+ }
+
+ if (c == '>') {
+ if (s.charAt(pos) == '=') {
+ types.push(XPathParser.GREATERTHANOREQUAL);
+ values.push(">=");
+ pos++;
+ c = s.charAt(pos++);
+ continue;
+ }
+ types.push(XPathParser.GREATERTHAN);
+ values.push('>');
+ c = s.charAt(pos++);
+ continue;
+ }
+
+ if (c == '_' || Utilities.isLetter(c.charCodeAt(0))) {
+ var name = c;
+ c = s.charAt(pos++);
+ while (Utilities.isNCNameChar(c.charCodeAt(0))) {
+ name += c;
+ c = s.charAt(pos++);
+ }
+ if (types.length > 0) {
+ var last = types[types.length - 1];
+ if (last != XPathParser.AT
+ && last != XPathParser.DOUBLECOLON
+ && last != XPathParser.LEFTPARENTHESIS
+ && last != XPathParser.LEFTBRACKET
+ && last != XPathParser.AND
+ && last != XPathParser.OR
+ && last != XPathParser.MOD
+ && last != XPathParser.DIV
+ && last != XPathParser.MULTIPLYOPERATOR
+ && last != XPathParser.SLASH
+ && last != XPathParser.DOUBLESLASH
+ && last != XPathParser.BAR
+ && last != XPathParser.PLUS
+ && last != XPathParser.MINUS
+ && last != XPathParser.EQUALS
+ && last != XPathParser.NOTEQUAL
+ && last != XPathParser.LESSTHAN
+ && last != XPathParser.LESSTHANOREQUAL
+ && last != XPathParser.GREATERTHAN
+ && last != XPathParser.GREATERTHANOREQUAL) {
+ if (name == "and") {
+ types.push(XPathParser.AND);
+ values.push(name);
+ continue;
+ }
+ if (name == "or") {
+ types.push(XPathParser.OR);
+ values.push(name);
+ continue;
+ }
+ if (name == "mod") {
+ types.push(XPathParser.MOD);
+ values.push(name);
+ continue;
+ }
+ if (name == "div") {
+ types.push(XPathParser.DIV);
+ values.push(name);
+ continue;
+ }
+ }
+ }
+ if (c == ':') {
+ if (s.charAt(pos) == '*') {
+ types.push(XPathParser.NCNAMECOLONASTERISK);
+ values.push(name + ":*");
+ pos++;
+ c = s.charAt(pos++);
+ continue;
+ }
+ if (s.charAt(pos) == '_' || Utilities.isLetter(s.charCodeAt(pos))) {
+ name += ':';
+ c = s.charAt(pos++);
+ while (Utilities.isNCNameChar(c.charCodeAt(0))) {
+ name += c;
+ c = s.charAt(pos++);
+ }
+ if (c == '(') {
+ types.push(XPathParser.FUNCTIONNAME);
+ values.push(name);
+ continue;
+ }
+ types.push(XPathParser.QNAME);
+ values.push(name);
+ continue;
+ }
+ if (s.charAt(pos) == ':') {
+ types.push(XPathParser.AXISNAME);
+ values.push(name);
+ continue;
+ }
+ }
+ if (c == '(') {
+ if (name == "comment" || name == "text" || name == "node") {
+ types.push(XPathParser.NODETYPE);
+ values.push(name);
+ continue;
+ }
+ if (name == "processing-instruction") {
+ if (s.charAt(pos) == ')') {
+ types.push(XPathParser.NODETYPE);
+ } else {
+ types.push(XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL);
+ }
+ values.push(name);
+ continue;
+ }
+ types.push(XPathParser.FUNCTIONNAME);
+ values.push(name);
+ continue;
+ }
+ types.push(XPathParser.QNAME);
+ values.push(name);
+ continue;
+ }
+
+ throw new Error("Unexpected character " + c);
+ }
+ types.push(1);
+ values.push("[EOF]");
+ return [types, values];
+};
+
+XPathParser.SHIFT = 's';
+XPathParser.REDUCE = 'r';
+XPathParser.ACCEPT = 'a';
+
+XPathParser.prototype.parse = function(s) {
+ var types;
+ var values;
+ var res = this.tokenize(s);
+ if (res == undefined) {
+ return undefined;
+ }
+ types = res[0];
+ values = res[1];
+ var tokenPos = 0;
+ var state = [];
+ var tokenType = [];
+ var tokenValue = [];
+ var s;
+ var a;
+ var t;
+
+ state.push(0);
+ tokenType.push(1);
+ tokenValue.push("_S");
+
+ a = types[tokenPos];
+ t = values[tokenPos++];
+ while (1) {
+ s = state[state.length - 1];
+ switch (XPathParser.actionTable[s].charAt(a - 1)) {
+ case XPathParser.SHIFT:
+ tokenType.push(-a);
+ tokenValue.push(t);
+ state.push(XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32);
+ a = types[tokenPos];
+ t = values[tokenPos++];
+ break;
+ case XPathParser.REDUCE:
+ var num = XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][1];
+ var rhs = [];
+ for (var i = 0; i < num; i++) {
+ tokenType.pop();
+ rhs.unshift(tokenValue.pop());
+ state.pop();
+ }
+ var s_ = state[state.length - 1];
+ tokenType.push(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0]);
+ if (this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32] == undefined) {
+ tokenValue.push(rhs[0]);
+ } else {
+ tokenValue.push(this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32](rhs));
+ }
+ state.push(XPathParser.gotoTable[s_].charCodeAt(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0] - 2) - 33);
+ break;
+ case XPathParser.ACCEPT:
+ return new XPath(tokenValue.pop());
+ default:
+ throw new Error("XPath parse error");
+ }
+ }
+};
+
+// XPath /////////////////////////////////////////////////////////////////////
+
+XPath.prototype = new Object();
+XPath.prototype.constructor = XPath;
+XPath.superclass = Object.prototype;
+
+function XPath(e) {
+ this.expression = e;
+}
+
+XPath.prototype.toString = function() {
+ return this.expression.toString();
+};
+
+function setIfUnset(obj, prop, value) {
+ if (!(prop in obj)) {
+ obj[prop] = value;
+ }
+}
+
+XPath.prototype.evaluate = function(c) {
+ c.contextNode = c.expressionContextNode;
+ c.contextSize = 1;
+ c.contextPosition = 1;
+
+ // [2017-11-25] Removed usage of .implementation.hasFeature() since it does
+ // not reliably detect HTML DOMs (always returns false in xmldom and true in browsers)
+ if (c.isHtml) {
+ setIfUnset(c, 'caseInsensitive', true);
+ setIfUnset(c, 'allowAnyNamespaceForNoPrefix', true);
+ }
+
+ setIfUnset(c, 'caseInsensitive', false);
+
+ return this.expression.evaluate(c);
+};
+
+XPath.XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
+XPath.XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
+
+// Expression ////////////////////////////////////////////////////////////////
+
+Expression.prototype = new Object();
+Expression.prototype.constructor = Expression;
+Expression.superclass = Object.prototype;
+
+function Expression() {
+}
+
+Expression.prototype.init = function() {
+};
+
+Expression.prototype.toString = function() {
+ return "";
+};
+
+Expression.prototype.evaluate = function(c) {
+ throw new Error("Could not evaluate expression.");
+};
+
+// UnaryOperation ////////////////////////////////////////////////////////////
+
+UnaryOperation.prototype = new Expression();
+UnaryOperation.prototype.constructor = UnaryOperation;
+UnaryOperation.superclass = Expression.prototype;
+
+function UnaryOperation(rhs) {
+ if (arguments.length > 0) {
+ this.init(rhs);
+ }
+}
+
+UnaryOperation.prototype.init = function(rhs) {
+ this.rhs = rhs;
+};
+
+// UnaryMinusOperation ///////////////////////////////////////////////////////
+
+UnaryMinusOperation.prototype = new UnaryOperation();
+UnaryMinusOperation.prototype.constructor = UnaryMinusOperation;
+UnaryMinusOperation.superclass = UnaryOperation.prototype;
+
+function UnaryMinusOperation(rhs) {
+ if (arguments.length > 0) {
+ this.init(rhs);
+ }
+}
+
+UnaryMinusOperation.prototype.init = function(rhs) {
+ UnaryMinusOperation.superclass.init.call(this, rhs);
+};
+
+UnaryMinusOperation.prototype.evaluate = function(c) {
+ return this.rhs.evaluate(c).number().negate();
+};
+
+UnaryMinusOperation.prototype.toString = function() {
+ return "-" + this.rhs.toString();
+};
+
+// BinaryOperation ///////////////////////////////////////////////////////////
+
+BinaryOperation.prototype = new Expression();
+BinaryOperation.prototype.constructor = BinaryOperation;
+BinaryOperation.superclass = Expression.prototype;
+
+function BinaryOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+BinaryOperation.prototype.init = function(lhs, rhs) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+};
+
+// OrOperation ///////////////////////////////////////////////////////////////
+
+OrOperation.prototype = new BinaryOperation();
+OrOperation.prototype.constructor = OrOperation;
+OrOperation.superclass = BinaryOperation.prototype;
+
+function OrOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+OrOperation.prototype.init = function(lhs, rhs) {
+ OrOperation.superclass.init.call(this, lhs, rhs);
+};
+
+OrOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " or " + this.rhs.toString() + ")";
+};
+
+OrOperation.prototype.evaluate = function(c) {
+ var b = this.lhs.evaluate(c).bool();
+ if (b.booleanValue()) {
+ return b;
+ }
+ return this.rhs.evaluate(c).bool();
+};
+
+// AndOperation //////////////////////////////////////////////////////////////
+
+AndOperation.prototype = new BinaryOperation();
+AndOperation.prototype.constructor = AndOperation;
+AndOperation.superclass = BinaryOperation.prototype;
+
+function AndOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+AndOperation.prototype.init = function(lhs, rhs) {
+ AndOperation.superclass.init.call(this, lhs, rhs);
+};
+
+AndOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " and " + this.rhs.toString() + ")";
+};
+
+AndOperation.prototype.evaluate = function(c) {
+ var b = this.lhs.evaluate(c).bool();
+ if (!b.booleanValue()) {
+ return b;
+ }
+ return this.rhs.evaluate(c).bool();
+};
+
+// EqualsOperation ///////////////////////////////////////////////////////////
+
+EqualsOperation.prototype = new BinaryOperation();
+EqualsOperation.prototype.constructor = EqualsOperation;
+EqualsOperation.superclass = BinaryOperation.prototype;
+
+function EqualsOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+EqualsOperation.prototype.init = function(lhs, rhs) {
+ EqualsOperation.superclass.init.call(this, lhs, rhs);
+};
+
+EqualsOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " = " + this.rhs.toString() + ")";
+};
+
+EqualsOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).equals(this.rhs.evaluate(c));
+};
+
+// NotEqualOperation /////////////////////////////////////////////////////////
+
+NotEqualOperation.prototype = new BinaryOperation();
+NotEqualOperation.prototype.constructor = NotEqualOperation;
+NotEqualOperation.superclass = BinaryOperation.prototype;
+
+function NotEqualOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+NotEqualOperation.prototype.init = function(lhs, rhs) {
+ NotEqualOperation.superclass.init.call(this, lhs, rhs);
+};
+
+NotEqualOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " != " + this.rhs.toString() + ")";
+};
+
+NotEqualOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).notequal(this.rhs.evaluate(c));
+};
+
+// LessThanOperation /////////////////////////////////////////////////////////
+
+LessThanOperation.prototype = new BinaryOperation();
+LessThanOperation.prototype.constructor = LessThanOperation;
+LessThanOperation.superclass = BinaryOperation.prototype;
+
+function LessThanOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+LessThanOperation.prototype.init = function(lhs, rhs) {
+ LessThanOperation.superclass.init.call(this, lhs, rhs);
+};
+
+LessThanOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).lessthan(this.rhs.evaluate(c));
+};
+
+LessThanOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " < " + this.rhs.toString() + ")";
+};
+
+// GreaterThanOperation //////////////////////////////////////////////////////
+
+GreaterThanOperation.prototype = new BinaryOperation();
+GreaterThanOperation.prototype.constructor = GreaterThanOperation;
+GreaterThanOperation.superclass = BinaryOperation.prototype;
+
+function GreaterThanOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+GreaterThanOperation.prototype.init = function(lhs, rhs) {
+ GreaterThanOperation.superclass.init.call(this, lhs, rhs);
+};
+
+GreaterThanOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).greaterthan(this.rhs.evaluate(c));
+};
+
+GreaterThanOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " > " + this.rhs.toString() + ")";
+};
+
+// LessThanOrEqualOperation //////////////////////////////////////////////////
+
+LessThanOrEqualOperation.prototype = new BinaryOperation();
+LessThanOrEqualOperation.prototype.constructor = LessThanOrEqualOperation;
+LessThanOrEqualOperation.superclass = BinaryOperation.prototype;
+
+function LessThanOrEqualOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+LessThanOrEqualOperation.prototype.init = function(lhs, rhs) {
+ LessThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
+};
+
+LessThanOrEqualOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).lessthanorequal(this.rhs.evaluate(c));
+};
+
+LessThanOrEqualOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " <= " + this.rhs.toString() + ")";
+};
+
+// GreaterThanOrEqualOperation ///////////////////////////////////////////////
+
+GreaterThanOrEqualOperation.prototype = new BinaryOperation();
+GreaterThanOrEqualOperation.prototype.constructor = GreaterThanOrEqualOperation;
+GreaterThanOrEqualOperation.superclass = BinaryOperation.prototype;
+
+function GreaterThanOrEqualOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+GreaterThanOrEqualOperation.prototype.init = function(lhs, rhs) {
+ GreaterThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
+};
+
+GreaterThanOrEqualOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).greaterthanorequal(this.rhs.evaluate(c));
+};
+
+GreaterThanOrEqualOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " >= " + this.rhs.toString() + ")";
+};
+
+// PlusOperation /////////////////////////////////////////////////////////////
+
+PlusOperation.prototype = new BinaryOperation();
+PlusOperation.prototype.constructor = PlusOperation;
+PlusOperation.superclass = BinaryOperation.prototype;
+
+function PlusOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+PlusOperation.prototype.init = function(lhs, rhs) {
+ PlusOperation.superclass.init.call(this, lhs, rhs);
+};
+
+PlusOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).number().plus(this.rhs.evaluate(c).number());
+};
+
+PlusOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " + " + this.rhs.toString() + ")";
+};
+
+// MinusOperation ////////////////////////////////////////////////////////////
+
+MinusOperation.prototype = new BinaryOperation();
+MinusOperation.prototype.constructor = MinusOperation;
+MinusOperation.superclass = BinaryOperation.prototype;
+
+function MinusOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+MinusOperation.prototype.init = function(lhs, rhs) {
+ MinusOperation.superclass.init.call(this, lhs, rhs);
+};
+
+MinusOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).number().minus(this.rhs.evaluate(c).number());
+};
+
+MinusOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " - " + this.rhs.toString() + ")";
+};
+
+// MultiplyOperation /////////////////////////////////////////////////////////
+
+MultiplyOperation.prototype = new BinaryOperation();
+MultiplyOperation.prototype.constructor = MultiplyOperation;
+MultiplyOperation.superclass = BinaryOperation.prototype;
+
+function MultiplyOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+MultiplyOperation.prototype.init = function(lhs, rhs) {
+ MultiplyOperation.superclass.init.call(this, lhs, rhs);
+};
+
+MultiplyOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).number().multiply(this.rhs.evaluate(c).number());
+};
+
+MultiplyOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " * " + this.rhs.toString() + ")";
+};
+
+// DivOperation //////////////////////////////////////////////////////////////
+
+DivOperation.prototype = new BinaryOperation();
+DivOperation.prototype.constructor = DivOperation;
+DivOperation.superclass = BinaryOperation.prototype;
+
+function DivOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+DivOperation.prototype.init = function(lhs, rhs) {
+ DivOperation.superclass.init.call(this, lhs, rhs);
+};
+
+DivOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).number().div(this.rhs.evaluate(c).number());
+};
+
+DivOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " div " + this.rhs.toString() + ")";
+};
+
+// ModOperation //////////////////////////////////////////////////////////////
+
+ModOperation.prototype = new BinaryOperation();
+ModOperation.prototype.constructor = ModOperation;
+ModOperation.superclass = BinaryOperation.prototype;
+
+function ModOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+ModOperation.prototype.init = function(lhs, rhs) {
+ ModOperation.superclass.init.call(this, lhs, rhs);
+};
+
+ModOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).number().mod(this.rhs.evaluate(c).number());
+};
+
+ModOperation.prototype.toString = function() {
+ return "(" + this.lhs.toString() + " mod " + this.rhs.toString() + ")";
+};
+
+// BarOperation //////////////////////////////////////////////////////////////
+
+BarOperation.prototype = new BinaryOperation();
+BarOperation.prototype.constructor = BarOperation;
+BarOperation.superclass = BinaryOperation.prototype;
+
+function BarOperation(lhs, rhs) {
+ if (arguments.length > 0) {
+ this.init(lhs, rhs);
+ }
+}
+
+BarOperation.prototype.init = function(lhs, rhs) {
+ BarOperation.superclass.init.call(this, lhs, rhs);
+};
+
+BarOperation.prototype.evaluate = function(c) {
+ return this.lhs.evaluate(c).nodeset().union(this.rhs.evaluate(c).nodeset());
+};
+
+BarOperation.prototype.toString = function() {
+ return map(toString, [this.lhs, this.rhs]).join(' | ');
+};
+
+// PathExpr //////////////////////////////////////////////////////////////////
+
+PathExpr.prototype = new Expression();
+PathExpr.prototype.constructor = PathExpr;
+PathExpr.superclass = Expression.prototype;
+
+function PathExpr(filter, filterPreds, locpath) {
+ if (arguments.length > 0) {
+ this.init(filter, filterPreds, locpath);
+ }
+}
+
+PathExpr.prototype.init = function(filter, filterPreds, locpath) {
+ PathExpr.superclass.init.call(this);
+ this.filter = filter;
+ this.filterPredicates = filterPreds;
+ this.locationPath = locpath;
+};
+
+/**
+ * Returns the topmost node of the tree containing node
+ */
+function findRoot(node) {
+ while (node && node.parentNode) {
+ node = node.parentNode;
+ }
+
+ return node;
+}
+
+PathExpr.applyPredicates = function (predicates, c, nodes) {
+ return reduce(function (inNodes, pred) {
+ var ctx = c.extend({ contextSize: inNodes.length });
+
+ return filter(function (node, i) {
+ return PathExpr.predicateMatches(pred, ctx.extend({ contextNode: node, contextPosition: i + 1 }));
+ }, inNodes);
+ }, nodes, predicates);
+};
+
+PathExpr.getRoot = function (xpc, nodes) {
+ var firstNode = nodes[0];
+
+ if (firstNode.nodeType === 9 /*Node.DOCUMENT_NODE*/) {
+ return firstNode;
+ }
+
+ if (xpc.virtualRoot) {
+ return xpc.virtualRoot;
+ }
+
+ var ownerDoc = firstNode.ownerDocument;
+
+ if (ownerDoc) {
+ return ownerDoc;
+ }
+
+ // IE 5.5 doesn't have ownerDocument?
+ var n = firstNode;
+ while (n.parentNode != null) {
+ n = n.parentNode;
+ }
+ return n;
+}
+
+PathExpr.applyStep = function (step, xpc, node) {
+ var self = this;
+ var newNodes = [];
+ xpc.contextNode = node;
+
+ switch (step.axis) {
+ case Step.ANCESTOR:
+ // look at all the ancestor nodes
+ if (xpc.contextNode === xpc.virtualRoot) {
+ break;
+ }
+ var m;
+ if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+ m = PathExpr.getOwnerElement(xpc.contextNode);
+ } else {
+ m = xpc.contextNode.parentNode;
+ }
+ while (m != null) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ if (m === xpc.virtualRoot) {
+ break;
+ }
+ m = m.parentNode;
+ }
+ break;
+
+ case Step.ANCESTORORSELF:
+ // look at all the ancestor nodes and the current node
+ for (var m = xpc.contextNode; m != null; m = m.nodeType == 2 /*Node.ATTRIBUTE_NODE*/ ? PathExpr.getOwnerElement(m) : m.parentNode) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ if (m === xpc.virtualRoot) {
+ break;
+ }
+ }
+ break;
+
+ case Step.ATTRIBUTE:
+ // look at the attributes
+ var nnm = xpc.contextNode.attributes;
+ if (nnm != null) {
+ for (var k = 0; k < nnm.length; k++) {
+ var m = nnm.item(k);
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ }
+ }
+ break;
+
+ case Step.CHILD:
+ // look at all child elements
+ for (var m = xpc.contextNode.firstChild; m != null; m = m.nextSibling) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ }
+ break;
+
+ case Step.DESCENDANT:
+ // look at all descendant nodes
+ var st = [ xpc.contextNode.firstChild ];
+ while (st.length > 0) {
+ for (var m = st.pop(); m != null; ) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ if (m.firstChild != null) {
+ st.push(m.nextSibling);
+ m = m.firstChild;
+ } else {
+ m = m.nextSibling;
+ }
+ }
+ }
+ break;
+
+ case Step.DESCENDANTORSELF:
+ // look at self
+ if (step.nodeTest.matches(xpc.contextNode, xpc)) {
+ newNodes.push(xpc.contextNode);
+ }
+ // look at all descendant nodes
+ var st = [ xpc.contextNode.firstChild ];
+ while (st.length > 0) {
+ for (var m = st.pop(); m != null; ) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ if (m.firstChild != null) {
+ st.push(m.nextSibling);
+ m = m.firstChild;
+ } else {
+ m = m.nextSibling;
+ }
+ }
+ }
+ break;
+
+ case Step.FOLLOWING:
+ if (xpc.contextNode === xpc.virtualRoot) {
+ break;
+ }
+ var st = [];
+ if (xpc.contextNode.firstChild != null) {
+ st.unshift(xpc.contextNode.firstChild);
+ } else {
+ st.unshift(xpc.contextNode.nextSibling);
+ }
+ for (var m = xpc.contextNode.parentNode; m != null && m.nodeType != 9 /*Node.DOCUMENT_NODE*/ && m !== xpc.virtualRoot; m = m.parentNode) {
+ st.unshift(m.nextSibling);
+ }
+ do {
+ for (var m = st.pop(); m != null; ) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ if (m.firstChild != null) {
+ st.push(m.nextSibling);
+ m = m.firstChild;
+ } else {
+ m = m.nextSibling;
+ }
+ }
+ } while (st.length > 0);
+ break;
+
+ case Step.FOLLOWINGSIBLING:
+ if (xpc.contextNode === xpc.virtualRoot) {
+ break;
+ }
+ for (var m = xpc.contextNode.nextSibling; m != null; m = m.nextSibling) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ }
+ break;
+
+ case Step.NAMESPACE:
+ var n = {};
+ if (xpc.contextNode.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+ n["xml"] = XPath.XML_NAMESPACE_URI;
+ n["xmlns"] = XPath.XMLNS_NAMESPACE_URI;
+ for (var m = xpc.contextNode; m != null && m.nodeType == 1 /*Node.ELEMENT_NODE*/; m = m.parentNode) {
+ for (var k = 0; k < m.attributes.length; k++) {
+ var attr = m.attributes.item(k);
+ var nm = String(attr.name);
+ if (nm == "xmlns") {
+ if (n[""] == undefined) {
+ n[""] = attr.value;
+ }
+ } else if (nm.length > 6 && nm.substring(0, 6) == "xmlns:") {
+ var pre = nm.substring(6, nm.length);
+ if (n[pre] == undefined) {
+ n[pre] = attr.value;
+ }
+ }
+ }
+ }
+ for (var pre in n) {
+ var nsn = new XPathNamespace(pre, n[pre], xpc.contextNode);
+ if (step.nodeTest.matches(nsn, xpc)) {
+ newNodes.push(nsn);
+ }
+ }
+ }
+ break;
+
+ case Step.PARENT:
+ m = null;
+ if (xpc.contextNode !== xpc.virtualRoot) {
+ if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+ m = PathExpr.getOwnerElement(xpc.contextNode);
+ } else {
+ m = xpc.contextNode.parentNode;
+ }
+ }
+ if (m != null && step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ break;
+
+ case Step.PRECEDING:
+ var st;
+ if (xpc.virtualRoot != null) {
+ st = [ xpc.virtualRoot ];
+ } else {
+ // cannot rely on .ownerDocument because the node may be in a document fragment
+ st = [findRoot(xpc.contextNode)];
+ }
+ outer: while (st.length > 0) {
+ for (var m = st.pop(); m != null; ) {
+ if (m == xpc.contextNode) {
+ break outer;
+ }
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.unshift(m);
+ }
+ if (m.firstChild != null) {
+ st.push(m.nextSibling);
+ m = m.firstChild;
+ } else {
+ m = m.nextSibling;
+ }
+ }
+ }
+ break;
+
+ case Step.PRECEDINGSIBLING:
+ if (xpc.contextNode === xpc.virtualRoot) {
+ break;
+ }
+ for (var m = xpc.contextNode.previousSibling; m != null; m = m.previousSibling) {
+ if (step.nodeTest.matches(m, xpc)) {
+ newNodes.push(m);
+ }
+ }
+ break;
+
+ case Step.SELF:
+ if (step.nodeTest.matches(xpc.contextNode, xpc)) {
+ newNodes.push(xpc.contextNode);
+ }
+ break;
+
+ default:
+ }
+
+ return newNodes;
+};
+
+PathExpr.applySteps = function (steps, xpc, nodes) {
+ return reduce(function (inNodes, step) {
+ return [].concat.apply([], map(function (node) {
+ return PathExpr.applyPredicates(step.predicates, xpc, PathExpr.applyStep(step, xpc, node));
+ }, inNodes));
+ }, nodes, steps);
+}
+
+PathExpr.prototype.applyFilter = function(c, xpc) {
+ if (!this.filter) {
+ return { nodes: [ c.contextNode ] };
+ }
+
+ var ns = this.filter.evaluate(c);
+
+ if (!Utilities.instance_of(ns, XNodeSet)) {
+ if (this.filterPredicates != null && this.filterPredicates.length > 0 || this.locationPath != null) {
+ throw new Error("Path expression filter must evaluate to a nodeset if predicates or location path are used");
+ }
+
+ return { nonNodes: ns };
+ }
+
+ return {
+ nodes: PathExpr.applyPredicates(this.filterPredicates || [], xpc, ns.toUnsortedArray())
+ };
+};
+
+PathExpr.applyLocationPath = function (locationPath, xpc, nodes) {
+ if (!locationPath) {
+ return nodes;
+ }
+
+ var startNodes = locationPath.absolute ? [ PathExpr.getRoot(xpc, nodes) ] : nodes;
+
+ return PathExpr.applySteps(locationPath.steps, xpc, startNodes);
+};
+
+PathExpr.prototype.evaluate = function(c) {
+ var xpc = assign(new XPathContext(), c);
+
+ var filterResult = this.applyFilter(c, xpc);
+
+ if ('nonNodes' in filterResult) {
+ return filterResult.nonNodes;
+ }
+
+ var ns = new XNodeSet();
+ ns.addArray(PathExpr.applyLocationPath(this.locationPath, xpc, filterResult.nodes));
+ return ns;
+};
+
+PathExpr.predicateMatches = function(pred, c) {
+ var res = pred.evaluate(c);
+
+ return Utilities.instance_of(res, XNumber)
+ ? c.contextPosition == res.numberValue()
+ : res.booleanValue();
+};
+
+PathExpr.predicateString = compose(wrap('[', ']'), toString);
+PathExpr.predicatesString = compose(join(''), map(PathExpr.predicateString));
+
+PathExpr.prototype.toString = function() {
+ if (this.filter != undefined) {
+ var filterStr = toString(this.filter);
+
+ if (Utilities.instance_of(this.filter, XString)) {
+ return wrap("'", "'", filterStr);
+ }
+ if (this.filterPredicates != undefined && this.filterPredicates.length) {
+ return wrap('(', ')', filterStr) +
+ PathExpr.predicatesString(this.filterPredicates);
+ }
+ if (this.locationPath != undefined) {
+ return filterStr +
+ (this.locationPath.absolute ? '' : '/') +
+ toString(this.locationPath);
+ }
+
+ return filterStr;
+ }
+
+ return toString(this.locationPath);
+};
+
+PathExpr.getOwnerElement = function(n) {
+ // DOM 2 has ownerElement
+ if (n.ownerElement) {
+ return n.ownerElement;
+ }
+ // DOM 1 Internet Explorer can use selectSingleNode (ironically)
+ try {
+ if (n.selectSingleNode) {
+ return n.selectSingleNode("..");
+ }
+ } catch (e) {
+ }
+ // Other DOM 1 implementations must use this egregious search
+ var doc = n.nodeType == 9 /*Node.DOCUMENT_NODE*/
+ ? n
+ : n.ownerDocument;
+ var elts = doc.getElementsByTagName("*");
+ for (var i = 0; i < elts.length; i++) {
+ var elt = elts.item(i);
+ var nnm = elt.attributes;
+ for (var j = 0; j < nnm.length; j++) {
+ var an = nnm.item(j);
+ if (an === n) {
+ return elt;
+ }
+ }
+ }
+ return null;
+};
+
+// LocationPath //////////////////////////////////////////////////////////////
+
+LocationPath.prototype = new Object();
+LocationPath.prototype.constructor = LocationPath;
+LocationPath.superclass = Object.prototype;
+
+function LocationPath(abs, steps) {
+ if (arguments.length > 0) {
+ this.init(abs, steps);
+ }
+}
+
+LocationPath.prototype.init = function(abs, steps) {
+ this.absolute = abs;
+ this.steps = steps;
+};
+
+LocationPath.prototype.toString = function() {
+ return (
+ (this.absolute ? '/' : '') +
+ map(toString, this.steps).join('/')
+ );
+};
+
+// Step //////////////////////////////////////////////////////////////////////
+
+Step.prototype = new Object();
+Step.prototype.constructor = Step;
+Step.superclass = Object.prototype;
+
+function Step(axis, nodetest, preds) {
+ if (arguments.length > 0) {
+ this.init(axis, nodetest, preds);
+ }
+}
+
+Step.prototype.init = function(axis, nodetest, preds) {
+ this.axis = axis;
+ this.nodeTest = nodetest;
+ this.predicates = preds;
+};
+
+Step.prototype.toString = function() {
+ return Step.STEPNAMES[this.axis] +
+ "::" +
+ this.nodeTest.toString() +
+ PathExpr.predicatesString(this.predicates);
+};
+
+
+Step.ANCESTOR = 0;
+Step.ANCESTORORSELF = 1;
+Step.ATTRIBUTE = 2;
+Step.CHILD = 3;
+Step.DESCENDANT = 4;
+Step.DESCENDANTORSELF = 5;
+Step.FOLLOWING = 6;
+Step.FOLLOWINGSIBLING = 7;
+Step.NAMESPACE = 8;
+Step.PARENT = 9;
+Step.PRECEDING = 10;
+Step.PRECEDINGSIBLING = 11;
+Step.SELF = 12;
+
+Step.STEPNAMES = reduce(function (acc, x) { return acc[x[0]] = x[1], acc; }, {}, [
+ [Step.ANCESTOR, 'ancestor'],
+ [Step.ANCESTORORSELF, 'ancestor-or-self'],
+ [Step.ATTRIBUTE, 'attribute'],
+ [Step.CHILD, 'child'],
+ [Step.DESCENDANT, 'descendant'],
+ [Step.DESCENDANTORSELF, 'descendant-or-self'],
+ [Step.FOLLOWING, 'following'],
+ [Step.FOLLOWINGSIBLING, 'following-sibling'],
+ [Step.NAMESPACE, 'namespace'],
+ [Step.PARENT, 'parent'],
+ [Step.PRECEDING, 'preceding'],
+ [Step.PRECEDINGSIBLING, 'preceding-sibling'],
+ [Step.SELF, 'self']
+ ]);
+
+// NodeTest //////////////////////////////////////////////////////////////////
+
+NodeTest.prototype = new Object();
+NodeTest.prototype.constructor = NodeTest;
+NodeTest.superclass = Object.prototype;
+
+function NodeTest(type, value) {
+ if (arguments.length > 0) {
+ this.init(type, value);
+ }
+}
+
+NodeTest.prototype.init = function(type, value) {
+ this.type = type;
+ this.value = value;
+};
+
+NodeTest.prototype.toString = function() {
+ return "";
+};
+
+NodeTest.prototype.matches = function (n, xpc) {
+ console.warn('unknown node test type');
+};
+
+NodeTest.NAMETESTANY = 0;
+NodeTest.NAMETESTPREFIXANY = 1;
+NodeTest.NAMETESTQNAME = 2;
+NodeTest.COMMENT = 3;
+NodeTest.TEXT = 4;
+NodeTest.PI = 5;
+NodeTest.NODE = 6;
+
+NodeTest.isNodeType = function (types){
+ return compose(includes(types), prop('nodeType'));
+};
+
+NodeTest.makeNodeTestType = function (type, members, ctor) {
+ var newType = ctor || function () {};
+
+ newType.prototype = new NodeTest(members.type);
+ newType.prototype.constructor = type;
+
+ for (var key in members) {
+ newType.prototype[key] = members[key];
+ }
+
+ return newType;
+};
+// create invariant node test for certain node types
+NodeTest.makeNodeTypeTest = function (type, nodeTypes, stringVal) {
+ return new (NodeTest.makeNodeTestType(type, {
+ matches: NodeTest.isNodeType(nodeTypes),
+ toString: always(stringVal)
+ }))();
+};
+
+NodeTest.hasPrefix = function (node) {
+ return node.prefix || (node.nodeName || node.tagName).indexOf(':') !== -1;
+};
+
+NodeTest.isElementOrAttribute = NodeTest.isNodeType([1, 2]);
+NodeTest.nameSpaceMatches = function (prefix, xpc, n) {
+ var nNamespace = (n.namespaceURI || '');
+
+ if (!prefix) {
+ return !nNamespace || (xpc.allowAnyNamespaceForNoPrefix && !NodeTest.hasPrefix(n));
+ }
+
+ var ns = xpc.namespaceResolver.getNamespace(prefix, xpc.expressionContextNode);
+
+ if (ns == null) {
+ throw new Error("Cannot resolve QName " + prefix);
+ }
+
+ return ns === nNamespace;
+};
+NodeTest.localNameMatches = function (localName, xpc, n) {
+ var nLocalName = (n.localName || n.nodeName);
+
+ return xpc.caseInsensitive
+ ? localName.toLowerCase() === nLocalName.toLowerCase()
+ : localName === nLocalName;
+};
+
+NodeTest.NameTestPrefixAny = NodeTest.makeNodeTestType(NodeTest.NAMETESTPREFIXANY, {
+ matches: function (n, xpc){
+ return NodeTest.isElementOrAttribute(n) &&
+ NodeTest.nameSpaceMatches(this.prefix, xpc, n);
+ },
+ toString: function () {
+ return this.prefix + ":*";
+ }
+}, function (prefix) { this.prefix = prefix; });
+
+NodeTest.NameTestQName = NodeTest.makeNodeTestType(NodeTest.NAMETESTQNAME, {
+ matches: function (n, xpc) {
+ return NodeTest.isNodeType([1, 2, XPathNamespace.XPATH_NAMESPACE_NODE])(n) &&
+ NodeTest.nameSpaceMatches(this.prefix, xpc, n) &&
+ NodeTest.localNameMatches(this.localName, xpc, n);
+ },
+ toString: function () {
+ return this.name;
+ }
+}, function (name) {
+ var nameParts = name.split(':');
+
+ this.name = name;
+ this.prefix = nameParts.length > 1 ? nameParts[0] : null;
+ this.localName = nameParts[nameParts.length > 1 ? 1 : 0];
+});
+
+NodeTest.PITest = NodeTest.makeNodeTestType(NodeTest.PI, {
+ matches: function (n, xpc) {
+ return NodeTest.isNodeType([7])(n) && (n.target || n.nodeName) === this.name;
+ },
+ toString: function () {
+ return wrap('processing-instruction("', '")', this.name);
+ }
+}, function (name) { this.name = name; })
+
+// singletons
+
+// elements, attributes, namespaces
+NodeTest.nameTestAny = NodeTest.makeNodeTypeTest(NodeTest.NAMETESTANY, [1, 2, XPathNamespace.XPATH_NAMESPACE_NODE], '*');
+// text, cdata
+NodeTest.textTest = NodeTest.makeNodeTypeTest(NodeTest.TEXT, [3, 4], 'text()');
+NodeTest.commentTest = NodeTest.makeNodeTypeTest(NodeTest.COMMENT, [8], 'comment()');
+// elements, attributes, text, cdata, PIs, comments, document nodes
+NodeTest.nodeTest = NodeTest.makeNodeTypeTest(NodeTest.NODE, [1, 2, 3, 4, 7, 8, 9], 'node()');
+NodeTest.anyPiTest = NodeTest.makeNodeTypeTest(NodeTest.PI, [7], 'processing-instruction()');
+
+// VariableReference /////////////////////////////////////////////////////////
+
+VariableReference.prototype = new Expression();
+VariableReference.prototype.constructor = VariableReference;
+VariableReference.superclass = Expression.prototype;
+
+function VariableReference(v) {
+ if (arguments.length > 0) {
+ this.init(v);
+ }
+}
+
+VariableReference.prototype.init = function(v) {
+ this.variable = v;
+};
+
+VariableReference.prototype.toString = function() {
+ return "$" + this.variable;
+};
+
+VariableReference.prototype.evaluate = function(c) {
+ var parts = Utilities.resolveQName(this.variable, c.namespaceResolver, c.contextNode, false);
+
+ if (parts[0] == null) {
+ throw new Error("Cannot resolve QName " + fn);
+ }
+ var result = c.variableResolver.getVariable(parts[1], parts[0]);
+ if (!result) {
+ throw XPathException.fromMessage("Undeclared variable: " + this.toString());
+ }
+ return result;
+};
+
+// FunctionCall //////////////////////////////////////////////////////////////
+
+FunctionCall.prototype = new Expression();
+FunctionCall.prototype.constructor = FunctionCall;
+FunctionCall.superclass = Expression.prototype;
+
+function FunctionCall(fn, args) {
+ if (arguments.length > 0) {
+ this.init(fn, args);
+ }
+}
+
+FunctionCall.prototype.init = function(fn, args) {
+ this.functionName = fn;
+ this.arguments = args;
+};
+
+FunctionCall.prototype.toString = function() {
+ var s = this.functionName + "(";
+ for (var i = 0; i < this.arguments.length; i++) {
+ if (i > 0) {
+ s += ", ";
+ }
+ s += this.arguments[i].toString();
+ }
+ return s + ")";
+};
+
+FunctionCall.prototype.evaluate = function(c) {
+ var f = FunctionResolver.getFunctionFromContext(this.functionName, c);
+
+ if (!f) {
+ throw new Error("Unknown function " + this.functionName);
+ }
+
+ var a = [c].concat(this.arguments);
+ return f.apply(c.functionResolver.thisArg, a);
+};
+
+// Operators /////////////////////////////////////////////////////////////////
+
+var Operators = new Object();
+
+Operators.equals = function(l, r) {
+ return l.equals(r);
+};
+
+Operators.notequal = function(l, r) {
+ return l.notequal(r);
+};
+
+Operators.lessthan = function(l, r) {
+ return l.lessthan(r);
+};
+
+Operators.greaterthan = function(l, r) {
+ return l.greaterthan(r);
+};
+
+Operators.lessthanorequal = function(l, r) {
+ return l.lessthanorequal(r);
+};
+
+Operators.greaterthanorequal = function(l, r) {
+ return l.greaterthanorequal(r);
+};
+
+// XString ///////////////////////////////////////////////////////////////////
+
+XString.prototype = new Expression();
+XString.prototype.constructor = XString;
+XString.superclass = Expression.prototype;
+
+function XString(s) {
+ if (arguments.length > 0) {
+ this.init(s);
+ }
+}
+
+XString.prototype.init = function(s) {
+ this.str = String(s);
+};
+
+XString.prototype.toString = function() {
+ return this.str;
+};
+
+XString.prototype.evaluate = function(c) {
+ return this;
+};
+
+XString.prototype.string = function() {
+ return this;
+};
+
+XString.prototype.number = function() {
+ return new XNumber(this.str);
+};
+
+XString.prototype.bool = function() {
+ return new XBoolean(this.str);
+};
+
+XString.prototype.nodeset = function() {
+ throw new Error("Cannot convert string to nodeset");
+};
+
+XString.prototype.stringValue = function() {
+ return this.str;
+};
+
+XString.prototype.numberValue = function() {
+ return this.number().numberValue();
+};
+
+XString.prototype.booleanValue = function() {
+ return this.bool().booleanValue();
+};
+
+XString.prototype.equals = function(r) {
+ if (Utilities.instance_of(r, XBoolean)) {
+ return this.bool().equals(r);
+ }
+ if (Utilities.instance_of(r, XNumber)) {
+ return this.number().equals(r);
+ }
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithString(this, Operators.equals);
+ }
+ return new XBoolean(this.str == r.str);
+};
+
+XString.prototype.notequal = function(r) {
+ if (Utilities.instance_of(r, XBoolean)) {
+ return this.bool().notequal(r);
+ }
+ if (Utilities.instance_of(r, XNumber)) {
+ return this.number().notequal(r);
+ }
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithString(this, Operators.notequal);
+ }
+ return new XBoolean(this.str != r.str);
+};
+
+XString.prototype.lessthan = function(r) {
+ return this.number().lessthan(r);
+};
+
+XString.prototype.greaterthan = function(r) {
+ return this.number().greaterthan(r);
+};
+
+XString.prototype.lessthanorequal = function(r) {
+ return this.number().lessthanorequal(r);
+};
+
+XString.prototype.greaterthanorequal = function(r) {
+ return this.number().greaterthanorequal(r);
+};
+
+// XNumber ///////////////////////////////////////////////////////////////////
+
+XNumber.prototype = new Expression();
+XNumber.prototype.constructor = XNumber;
+XNumber.superclass = Expression.prototype;
+
+function XNumber(n) {
+ if (arguments.length > 0) {
+ this.init(n);
+ }
+}
+
+XNumber.prototype.init = function(n) {
+ this.num = typeof n === "string" ? this.parse(n) : Number(n);
+};
+
+XNumber.prototype.numberFormat = /^\s*-?[0-9]*\.?[0-9]+\s*$/;
+
+XNumber.prototype.parse = function(s) {
+ // XPath representation of numbers is more restrictive than what Number() or parseFloat() allow
+ return this.numberFormat.test(s) ? parseFloat(s) : Number.NaN;
+};
+
+function padSmallNumber(numberStr) {
+ var parts = numberStr.split('e-');
+ var base = parts[0].replace('.', '');
+ var exponent = Number(parts[1]);
+
+ for (var i = 0; i < exponent - 1; i += 1) {
+ base = '0' + base;
+ }
+
+ return '0.' + base;
+}
+
+function padLargeNumber(numberStr) {
+ var parts = numberStr.split('e');
+ var base = parts[0].replace('.', '');
+ var exponent = Number(parts[1]);
+ var zerosToAppend = exponent + 1 - base.length;
+
+ for (var i = 0; i < zerosToAppend; i += 1){
+ base += '0';
+ }
+
+ return base;
+}
+
+XNumber.prototype.toString = function() {
+ var strValue = this.num.toString();
+
+ if (strValue.indexOf('e-') !== -1) {
+ return padSmallNumber(strValue);
+ }
+
+ if (strValue.indexOf('e') !== -1) {
+ return padLargeNumber(strValue);
+ }
+
+ return strValue;
+};
+
+XNumber.prototype.evaluate = function(c) {
+ return this;
+};
+
+XNumber.prototype.string = function() {
+
+
+ return new XString(this.toString());
+};
+
+XNumber.prototype.number = function() {
+ return this;
+};
+
+XNumber.prototype.bool = function() {
+ return new XBoolean(this.num);
+};
+
+XNumber.prototype.nodeset = function() {
+ throw new Error("Cannot convert number to nodeset");
+};
+
+XNumber.prototype.stringValue = function() {
+ return this.string().stringValue();
+};
+
+XNumber.prototype.numberValue = function() {
+ return this.num;
+};
+
+XNumber.prototype.booleanValue = function() {
+ return this.bool().booleanValue();
+};
+
+XNumber.prototype.negate = function() {
+ return new XNumber(-this.num);
+};
+
+XNumber.prototype.equals = function(r) {
+ if (Utilities.instance_of(r, XBoolean)) {
+ return this.bool().equals(r);
+ }
+ if (Utilities.instance_of(r, XString)) {
+ return this.equals(r.number());
+ }
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithNumber(this, Operators.equals);
+ }
+ return new XBoolean(this.num == r.num);
+};
+
+XNumber.prototype.notequal = function(r) {
+ if (Utilities.instance_of(r, XBoolean)) {
+ return this.bool().notequal(r);
+ }
+ if (Utilities.instance_of(r, XString)) {
+ return this.notequal(r.number());
+ }
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithNumber(this, Operators.notequal);
+ }
+ return new XBoolean(this.num != r.num);
+};
+
+XNumber.prototype.lessthan = function(r) {
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithNumber(this, Operators.greaterthan);
+ }
+ if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+ return this.lessthan(r.number());
+ }
+ return new XBoolean(this.num < r.num);
+};
+
+XNumber.prototype.greaterthan = function(r) {
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithNumber(this, Operators.lessthan);
+ }
+ if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+ return this.greaterthan(r.number());
+ }
+ return new XBoolean(this.num > r.num);
+};
+
+XNumber.prototype.lessthanorequal = function(r) {
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithNumber(this, Operators.greaterthanorequal);
+ }
+ if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+ return this.lessthanorequal(r.number());
+ }
+ return new XBoolean(this.num <= r.num);
+};
+
+XNumber.prototype.greaterthanorequal = function(r) {
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithNumber(this, Operators.lessthanorequal);
+ }
+ if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+ return this.greaterthanorequal(r.number());
+ }
+ return new XBoolean(this.num >= r.num);
+};
+
+XNumber.prototype.plus = function(r) {
+ return new XNumber(this.num + r.num);
+};
+
+XNumber.prototype.minus = function(r) {
+ return new XNumber(this.num - r.num);
+};
+
+XNumber.prototype.multiply = function(r) {
+ return new XNumber(this.num * r.num);
+};
+
+XNumber.prototype.div = function(r) {
+ return new XNumber(this.num / r.num);
+};
+
+XNumber.prototype.mod = function(r) {
+ return new XNumber(this.num % r.num);
+};
+
+// XBoolean //////////////////////////////////////////////////////////////////
+
+XBoolean.prototype = new Expression();
+XBoolean.prototype.constructor = XBoolean;
+XBoolean.superclass = Expression.prototype;
+
+function XBoolean(b) {
+ if (arguments.length > 0) {
+ this.init(b);
+ }
+}
+
+XBoolean.prototype.init = function(b) {
+ this.b = Boolean(b);
+};
+
+XBoolean.prototype.toString = function() {
+ return this.b.toString();
+};
+
+XBoolean.prototype.evaluate = function(c) {
+ return this;
+};
+
+XBoolean.prototype.string = function() {
+ return new XString(this.b);
+};
+
+XBoolean.prototype.number = function() {
+ return new XNumber(this.b);
+};
+
+XBoolean.prototype.bool = function() {
+ return this;
+};
+
+XBoolean.prototype.nodeset = function() {
+ throw new Error("Cannot convert boolean to nodeset");
+};
+
+XBoolean.prototype.stringValue = function() {
+ return this.string().stringValue();
+};
+
+XBoolean.prototype.numberValue = function() {
+ return this.number().numberValue();
+};
+
+XBoolean.prototype.booleanValue = function() {
+ return this.b;
+};
+
+XBoolean.prototype.not = function() {
+ return new XBoolean(!this.b);
+};
+
+XBoolean.prototype.equals = function(r) {
+ if (Utilities.instance_of(r, XString) || Utilities.instance_of(r, XNumber)) {
+ return this.equals(r.bool());
+ }
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithBoolean(this, Operators.equals);
+ }
+ return new XBoolean(this.b == r.b);
+};
+
+XBoolean.prototype.notequal = function(r) {
+ if (Utilities.instance_of(r, XString) || Utilities.instance_of(r, XNumber)) {
+ return this.notequal(r.bool());
+ }
+ if (Utilities.instance_of(r, XNodeSet)) {
+ return r.compareWithBoolean(this, Operators.notequal);
+ }
+ return new XBoolean(this.b != r.b);
+};
+
+XBoolean.prototype.lessthan = function(r) {
+ return this.number().lessthan(r);
+};
+
+XBoolean.prototype.greaterthan = function(r) {
+ return this.number().greaterthan(r);
+};
+
+XBoolean.prototype.lessthanorequal = function(r) {
+ return this.number().lessthanorequal(r);
+};
+
+XBoolean.prototype.greaterthanorequal = function(r) {
+ return this.number().greaterthanorequal(r);
+};
+
+XBoolean.true_ = new XBoolean(true);
+XBoolean.false_ = new XBoolean(false);
+
+// AVLTree ///////////////////////////////////////////////////////////////////
+
+AVLTree.prototype = new Object();
+AVLTree.prototype.constructor = AVLTree;
+AVLTree.superclass = Object.prototype;
+
+function AVLTree(n) {
+ this.init(n);
+}
+
+AVLTree.prototype.init = function(n) {
+ this.left = null;
+ this.right = null;
+ this.node = n;
+ this.depth = 1;
+};
+
+AVLTree.prototype.balance = function() {
+ var ldepth = this.left == null ? 0 : this.left.depth;
+ var rdepth = this.right == null ? 0 : this.right.depth;
+
+ if (ldepth > rdepth + 1) {
+ // LR or LL rotation
+ var lldepth = this.left.left == null ? 0 : this.left.left.depth;
+ var lrdepth = this.left.right == null ? 0 : this.left.right.depth;
+
+ if (lldepth < lrdepth) {
+ // LR rotation consists of a RR rotation of the left child
+ this.left.rotateRR();
+ // plus a LL rotation of this node, which happens anyway
+ }
+ this.rotateLL();
+ } else if (ldepth + 1 < rdepth) {
+ // RR or RL rorarion
+ var rrdepth = this.right.right == null ? 0 : this.right.right.depth;
+ var rldepth = this.right.left == null ? 0 : this.right.left.depth;
+
+ if (rldepth > rrdepth) {
+ // RR rotation consists of a LL rotation of the right child
+ this.right.rotateLL();
+ // plus a RR rotation of this node, which happens anyway
+ }
+ this.rotateRR();
+ }
+};
+
+AVLTree.prototype.rotateLL = function() {
+ // the left side is too long => rotate from the left (_not_ leftwards)
+ var nodeBefore = this.node;
+ var rightBefore = this.right;
+ this.node = this.left.node;
+ this.right = this.left;
+ this.left = this.left.left;
+ this.right.left = this.right.right;
+ this.right.right = rightBefore;
+ this.right.node = nodeBefore;
+ this.right.updateInNewLocation();
+ this.updateInNewLocation();
+};
+
+AVLTree.prototype.rotateRR = function() {
+ // the right side is too long => rotate from the right (_not_ rightwards)
+ var nodeBefore = this.node;
+ var leftBefore = this.left;
+ this.node = this.right.node;
+ this.left = this.right;
+ this.right = this.right.right;
+ this.left.right = this.left.left;
+ this.left.left = leftBefore;
+ this.left.node = nodeBefore;
+ this.left.updateInNewLocation();
+ this.updateInNewLocation();
+};
+
+AVLTree.prototype.updateInNewLocation = function() {
+ this.getDepthFromChildren();
+};
+
+AVLTree.prototype.getDepthFromChildren = function() {
+ this.depth = this.node == null ? 0 : 1;
+ if (this.left != null) {
+ this.depth = this.left.depth + 1;
+ }
+ if (this.right != null && this.depth <= this.right.depth) {
+ this.depth = this.right.depth + 1;
+ }
+};
+
+function nodeOrder(n1, n2) {
+ if (n1 === n2) {
+ return 0;
+ }
+
+ if (n1.compareDocumentPosition) {
+ var cpos = n1.compareDocumentPosition(n2);
+
+ if (cpos & 0x01) {
+ // not in the same document; return an arbitrary result (is there a better way to do this)
+ return 1;
+ }
+ if (cpos & 0x0A) {
+ // n2 precedes or contains n1
+ return 1;
+ }
+ if (cpos & 0x14) {
+ // n2 follows or is contained by n1
+ return -1;
+ }
+
+ return 0;
+ }
+
+ var d1 = 0,
+ d2 = 0;
+ for (var m1 = n1; m1 != null; m1 = m1.parentNode || m1.ownerElement) {
+ d1++;
+ }
+ for (var m2 = n2; m2 != null; m2 = m2.parentNode || m2.ownerElement) {
+ d2++;
+ }
+
+ // step up to same depth
+ if (d1 > d2) {
+ while (d1 > d2) {
+ n1 = n1.parentNode || n1.ownerElement;
+ d1--;
+ }
+ if (n1 === n2) {
+ return 1;
+ }
+ } else if (d2 > d1) {
+ while (d2 > d1) {
+ n2 = n2.parentNode || n2.ownerElement;
+ d2--;
+ }
+ if (n1 === n2) {
+ return -1;
+ }
+ }
+
+ var n1Par = n1.parentNode || n1.ownerElement,
+ n2Par = n2.parentNode || n2.ownerElement;
+
+ // find common parent
+ while (n1Par !== n2Par) {
+ n1 = n1Par;
+ n2 = n2Par;
+ n1Par = n1.parentNode || n1.ownerElement;
+ n2Par = n2.parentNode || n2.ownerElement;
+ }
+
+ var n1isAttr = Utilities.isAttribute(n1);
+ var n2isAttr = Utilities.isAttribute(n2);
+
+ if (n1isAttr && !n2isAttr) {
+ return -1;
+ }
+ if (!n1isAttr && n2isAttr) {
+ return 1;
+ }
+
+ if(n1Par) {
+ var cn = n1isAttr ? n1Par.attributes : n1Par.childNodes,
+ len = cn.length;
+ for (var i = 0; i < len; i += 1) {
+ var n = cn[i];
+ if (n === n1) {
+ return -1;
+ }
+ if (n === n2) {
+ return 1;
+ }
+ }
+ }
+
+ throw new Error('Unexpected: could not determine node order');
+}
+
+AVLTree.prototype.add = function(n) {
+ if (n === this.node) {
+ return false;
+ }
+
+ var o = nodeOrder(n, this.node);
+
+ var ret = false;
+ if (o == -1) {
+ if (this.left == null) {
+ this.left = new AVLTree(n);
+ ret = true;
+ } else {
+ ret = this.left.add(n);
+ if (ret) {
+ this.balance();
+ }
+ }
+ } else if (o == 1) {
+ if (this.right == null) {
+ this.right = new AVLTree(n);
+ ret = true;
+ } else {
+ ret = this.right.add(n);
+ if (ret) {
+ this.balance();
+ }
+ }
+ }
+
+ if (ret) {
+ this.getDepthFromChildren();
+ }
+ return ret;
+};
+
+// XNodeSet //////////////////////////////////////////////////////////////////
+
+XNodeSet.prototype = new Expression();
+XNodeSet.prototype.constructor = XNodeSet;
+XNodeSet.superclass = Expression.prototype;
+
+function XNodeSet() {
+ this.init();
+}
+
+XNodeSet.prototype.init = function() {
+ this.tree = null;
+ this.nodes = [];
+ this.size = 0;
+};
+
+XNodeSet.prototype.toString = function() {
+ var p = this.first();
+ if (p == null) {
+ return "";
+ }
+ return this.stringForNode(p);
+};
+
+XNodeSet.prototype.evaluate = function(c) {
+ return this;
+};
+
+XNodeSet.prototype.string = function() {
+ return new XString(this.toString());
+};
+
+XNodeSet.prototype.stringValue = function() {
+ return this.toString();
+};
+
+XNodeSet.prototype.number = function() {
+ return new XNumber(this.string());
+};
+
+XNodeSet.prototype.numberValue = function() {
+ return Number(this.string());
+};
+
+XNodeSet.prototype.bool = function() {
+ return new XBoolean(this.booleanValue());
+};
+
+XNodeSet.prototype.booleanValue = function() {
+ return !!this.size;
+};
+
+XNodeSet.prototype.nodeset = function() {
+ return this;
+};
+
+XNodeSet.prototype.stringForNode = function(n) {
+ if (n.nodeType == 9 /*Node.DOCUMENT_NODE*/ ||
+ n.nodeType == 1 /*Node.ELEMENT_NODE */ ||
+ n.nodeType === 11 /*Node.DOCUMENT_FRAGMENT*/) {
+ return this.stringForContainerNode(n);
+ }
+ if (n.nodeType === 2 /* Node.ATTRIBUTE_NODE */) {
+ return n.value || n.nodeValue;
+ }
+ if (n.isNamespaceNode) {
+ return n.namespace;
+ }
+ return n.nodeValue;
+};
+
+XNodeSet.prototype.stringForContainerNode = function(n) {
+ var s = "";
+ for (var n2 = n.firstChild; n2 != null; n2 = n2.nextSibling) {
+ var nt = n2.nodeType;
+ // Element, Text, CDATA, Document, Document Fragment
+ if (nt === 1 || nt === 3 || nt === 4 || nt === 9 || nt === 11) {
+ s += this.stringForNode(n2);
+ }
+ }
+ return s;
+};
+
+XNodeSet.prototype.buildTree = function () {
+ if (!this.tree && this.nodes.length) {
+ this.tree = new AVLTree(this.nodes[0]);
+ for (var i = 1; i < this.nodes.length; i += 1) {
+ this.tree.add(this.nodes[i]);
+ }
+ }
+
+ return this.tree;
+};
+
+XNodeSet.prototype.first = function() {
+ var p = this.buildTree();
+ if (p == null) {
+ return null;
+ }
+ while (p.left != null) {
+ p = p.left;
+ }
+ return p.node;
+};
+
+XNodeSet.prototype.add = function(n) {
+ for (var i = 0; i < this.nodes.length; i += 1) {
+ if (n === this.nodes[i]) {
+ return;
+ }
+ }
+
+ this.tree = null;
+ this.nodes.push(n);
+ this.size += 1;
+};
+
+XNodeSet.prototype.addArray = function(ns) {
+ var self = this;
+
+ forEach(function (x) { self.add(x); }, ns);
+};
+
+/**
+ * Returns an array of the node set's contents in document order
+ */
+XNodeSet.prototype.toArray = function() {
+ var a = [];
+ this.toArrayRec(this.buildTree(), a);
+ return a;
+};
+
+XNodeSet.prototype.toArrayRec = function(t, a) {
+ if (t != null) {
+ this.toArrayRec(t.left, a);
+ a.push(t.node);
+ this.toArrayRec(t.right, a);
+ }
+};
+
+/**
+ * Returns an array of the node set's contents in arbitrary order
+ */
+XNodeSet.prototype.toUnsortedArray = function () {
+ return this.nodes.slice();
+};
+
+XNodeSet.prototype.compareWithString = function(r, o) {
+ var a = this.toUnsortedArray();
+ for (var i = 0; i < a.length; i++) {
+ var n = a[i];
+ var l = new XString(this.stringForNode(n));
+ var res = o(l, r);
+ if (res.booleanValue()) {
+ return res;
+ }
+ }
+ return new XBoolean(false);
+};
+
+XNodeSet.prototype.compareWithNumber = function(r, o) {
+ var a = this.toUnsortedArray();
+ for (var i = 0; i < a.length; i++) {
+ var n = a[i];
+ var l = new XNumber(this.stringForNode(n));
+ var res = o(l, r);
+ if (res.booleanValue()) {
+ return res;
+ }
+ }
+ return new XBoolean(false);
+};
+
+XNodeSet.prototype.compareWithBoolean = function(r, o) {
+ return o(this.bool(), r);
+};
+
+XNodeSet.prototype.compareWithNodeSet = function(r, o) {
+ var arr = this.toUnsortedArray();
+ var oInvert = function (lop, rop) { return o(rop, lop); };
+
+ for (var i = 0; i < arr.length; i++) {
+ var l = new XString(this.stringForNode(arr[i]));
+
+ var res = r.compareWithString(l, oInvert);
+ if (res.booleanValue()) {
+ return res;
+ }
+ }
+
+ return new XBoolean(false);
+};
+
+XNodeSet.compareWith = curry(function (o, r) {
+ if (Utilities.instance_of(r, XString)) {
+ return this.compareWithString(r, o);
+ }
+ if (Utilities.instance_of(r, XNumber)) {
+ return this.compareWithNumber(r, o);
+ }
+ if (Utilities.instance_of(r, XBoolean)) {
+ return this.compareWithBoolean(r, o);
+ }
+ return this.compareWithNodeSet(r, o);
+});
+
+XNodeSet.prototype.equals = XNodeSet.compareWith(Operators.equals);
+XNodeSet.prototype.notequal = XNodeSet.compareWith(Operators.notequal);
+XNodeSet.prototype.lessthan = XNodeSet.compareWith(Operators.lessthan);
+XNodeSet.prototype.greaterthan = XNodeSet.compareWith(Operators.greaterthan);
+XNodeSet.prototype.lessthanorequal = XNodeSet.compareWith(Operators.lessthanorequal);
+XNodeSet.prototype.greaterthanorequal = XNodeSet.compareWith(Operators.greaterthanorequal);
+
+XNodeSet.prototype.union = function(r) {
+ var ns = new XNodeSet();
+ ns.addArray(this.toUnsortedArray());
+ ns.addArray(r.toUnsortedArray());
+ return ns;
+};
+
+// XPathNamespace ////////////////////////////////////////////////////////////
+
+XPathNamespace.prototype = new Object();
+XPathNamespace.prototype.constructor = XPathNamespace;
+XPathNamespace.superclass = Object.prototype;
+
+function XPathNamespace(pre, ns, p) {
+ this.isXPathNamespace = true;
+ this.ownerDocument = p.ownerDocument;
+ this.nodeName = "#namespace";
+ this.prefix = pre;
+ this.localName = pre;
+ this.namespaceURI = ns;
+ this.nodeValue = ns;
+ this.ownerElement = p;
+ this.nodeType = XPathNamespace.XPATH_NAMESPACE_NODE;
+}
+
+XPathNamespace.prototype.toString = function() {
+ return "{ \"" + this.prefix + "\", \"" + this.namespaceURI + "\" }";
+};
+
+// XPathContext //////////////////////////////////////////////////////////////
+
+XPathContext.prototype = new Object();
+XPathContext.prototype.constructor = XPathContext;
+XPathContext.superclass = Object.prototype;
+
+function XPathContext(vr, nr, fr) {
+ this.variableResolver = vr != null ? vr : new VariableResolver();
+ this.namespaceResolver = nr != null ? nr : new NamespaceResolver();
+ this.functionResolver = fr != null ? fr : new FunctionResolver();
+}
+
+XPathContext.prototype.extend = function (newProps) {
+ return assign(new XPathContext(), this, newProps);
+};
+
+// VariableResolver //////////////////////////////////////////////////////////
+
+VariableResolver.prototype = new Object();
+VariableResolver.prototype.constructor = VariableResolver;
+VariableResolver.superclass = Object.prototype;
+
+function VariableResolver() {
+}
+
+VariableResolver.prototype.getVariable = function(ln, ns) {
+ return null;
+};
+
+// FunctionResolver //////////////////////////////////////////////////////////
+
+FunctionResolver.prototype = new Object();
+FunctionResolver.prototype.constructor = FunctionResolver;
+FunctionResolver.superclass = Object.prototype;
+
+function FunctionResolver(thisArg) {
+ this.thisArg = thisArg != null ? thisArg : Functions;
+ this.functions = new Object();
+ this.addStandardFunctions();
+}
+
+FunctionResolver.prototype.addStandardFunctions = function() {
+ this.functions["{}last"] = Functions.last;
+ this.functions["{}position"] = Functions.position;
+ this.functions["{}count"] = Functions.count;
+ this.functions["{}id"] = Functions.id;
+ this.functions["{}local-name"] = Functions.localName;
+ this.functions["{}namespace-uri"] = Functions.namespaceURI;
+ this.functions["{}name"] = Functions.name;
+ this.functions["{}string"] = Functions.string;
+ this.functions["{}concat"] = Functions.concat;
+ this.functions["{}starts-with"] = Functions.startsWith;
+ this.functions["{}contains"] = Functions.contains;
+ this.functions["{}substring-before"] = Functions.substringBefore;
+ this.functions["{}substring-after"] = Functions.substringAfter;
+ this.functions["{}substring"] = Functions.substring;
+ this.functions["{}string-length"] = Functions.stringLength;
+ this.functions["{}normalize-space"] = Functions.normalizeSpace;
+ this.functions["{}translate"] = Functions.translate;
+ this.functions["{}boolean"] = Functions.boolean_;
+ this.functions["{}not"] = Functions.not;
+ this.functions["{}true"] = Functions.true_;
+ this.functions["{}false"] = Functions.false_;
+ this.functions["{}lang"] = Functions.lang;
+ this.functions["{}number"] = Functions.number;
+ this.functions["{}sum"] = Functions.sum;
+ this.functions["{}floor"] = Functions.floor;
+ this.functions["{}ceiling"] = Functions.ceiling;
+ this.functions["{}round"] = Functions.round;
+};
+
+FunctionResolver.prototype.addFunction = function(ns, ln, f) {
+ this.functions["{" + ns + "}" + ln] = f;
+};
+
+FunctionResolver.getFunctionFromContext = function(qName, context) {
+ var parts = Utilities.resolveQName(qName, context.namespaceResolver, context.contextNode, false);
+
+ if (parts[0] === null) {
+ throw new Error("Cannot resolve QName " + name);
+ }
+
+ return context.functionResolver.getFunction(parts[1], parts[0]);
+};
+
+FunctionResolver.prototype.getFunction = function(localName, namespace) {
+ return this.functions["{" + namespace + "}" + localName];
+};
+
+// NamespaceResolver /////////////////////////////////////////////////////////
+
+NamespaceResolver.prototype = new Object();
+NamespaceResolver.prototype.constructor = NamespaceResolver;
+NamespaceResolver.superclass = Object.prototype;
+
+function NamespaceResolver() {
+}
+
+NamespaceResolver.prototype.getNamespace = function(prefix, n) {
+ if (prefix == "xml") {
+ return XPath.XML_NAMESPACE_URI;
+ } else if (prefix == "xmlns") {
+ return XPath.XMLNS_NAMESPACE_URI;
+ }
+ if (n.nodeType == 9 /*Node.DOCUMENT_NODE*/) {
+ n = n.documentElement;
+ } else if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+ n = PathExpr.getOwnerElement(n);
+ } else if (n.nodeType != 1 /*Node.ELEMENT_NODE*/) {
+ n = n.parentNode;
+ }
+ while (n != null && n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+ var nnm = n.attributes;
+ for (var i = 0; i < nnm.length; i++) {
+ var a = nnm.item(i);
+ var aname = a.name || a.nodeName;
+ if ((aname === "xmlns" && prefix === "")
+ || aname === "xmlns:" + prefix) {
+ return String(a.value || a.nodeValue);
+ }
+ }
+ n = n.parentNode;
+ }
+ return null;
+};
+
+// Functions /////////////////////////////////////////////////////////////////
+
+var Functions = new Object();
+
+Functions.last = function(c) {
+ if (arguments.length != 1) {
+ throw new Error("Function last expects ()");
+ }
+
+ return new XNumber(c.contextSize);
+};
+
+Functions.position = function(c) {
+ if (arguments.length != 1) {
+ throw new Error("Function position expects ()");
+ }
+
+ return new XNumber(c.contextPosition);
+};
+
+Functions.count = function() {
+ var c = arguments[0];
+ var ns;
+ if (arguments.length != 2 || !Utilities.instance_of(ns = arguments[1].evaluate(c), XNodeSet)) {
+ throw new Error("Function count expects (node-set)");
+ }
+ return new XNumber(ns.size);
+};
+
+Functions.id = function() {
+ var c = arguments[0];
+ var id;
+ if (arguments.length != 2) {
+ throw new Error("Function id expects (object)");
+ }
+ id = arguments[1].evaluate(c);
+ if (Utilities.instance_of(id, XNodeSet)) {
+ id = id.toArray().join(" ");
+ } else {
+ id = id.stringValue();
+ }
+ var ids = id.split(/[\x0d\x0a\x09\x20]+/);
+ var count = 0;
+ var ns = new XNodeSet();
+ var doc = c.contextNode.nodeType == 9 /*Node.DOCUMENT_NODE*/
+ ? c.contextNode
+ : c.contextNode.ownerDocument;
+ for (var i = 0; i < ids.length; i++) {
+ var n;
+ if (doc.getElementById) {
+ n = doc.getElementById(ids[i]);
+ } else {
+ n = Utilities.getElementById(doc, ids[i]);
+ }
+ if (n != null) {
+ ns.add(n);
+ count++;
+ }
+ }
+ return ns;
+};
+
+Functions.localName = function(c, eNode) {
+ var n;
+
+ if (arguments.length == 1) {
+ n = c.contextNode;
+ } else if (arguments.length == 2) {
+ n = eNode.evaluate(c).first();
+ } else {
+ throw new Error("Function local-name expects (node-set?)");
+ }
+
+ if (n == null) {
+ return new XString("");
+ }
+
+ return new XString(n.localName || // standard elements and attributes
+ n.baseName || // IE
+ n.target || // processing instructions
+ n.nodeName || // DOM1 elements
+ ""); // fallback
+};
+
+Functions.namespaceURI = function() {
+ var c = arguments[0];
+ var n;
+ if (arguments.length == 1) {
+ n = c.contextNode;
+ } else if (arguments.length == 2) {
+ n = arguments[1].evaluate(c).first();
+ } else {
+ throw new Error("Function namespace-uri expects (node-set?)");
+ }
+ if (n == null) {
+ return new XString("");
+ }
+ return new XString(n.namespaceURI);
+};
+
+Functions.name = function() {
+ var c = arguments[0];
+ var n;
+ if (arguments.length == 1) {
+ n = c.contextNode;
+ } else if (arguments.length == 2) {
+ n = arguments[1].evaluate(c).first();
+ } else {
+ throw new Error("Function name expects (node-set?)");
+ }
+ if (n == null) {
+ return new XString("");
+ }
+ if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+ return new XString(n.nodeName);
+ } else if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+ return new XString(n.name || n.nodeName);
+ } else if (n.nodeType === 7 /*Node.PROCESSING_INSTRUCTION_NODE*/) {
+ return new XString(n.target || n.nodeName);
+ } else if (n.localName == null) {
+ return new XString("");
+ } else {
+ return new XString(n.localName);
+ }
+};
+
+Functions.string = function() {
+ var c = arguments[0];
+ if (arguments.length == 1) {
+ return new XString(XNodeSet.prototype.stringForNode(c.contextNode));
+ } else if (arguments.length == 2) {
+ return arguments[1].evaluate(c).string();
+ }
+ throw new Error("Function string expects (object?)");
+};
+
+Functions.concat = function(c) {
+ if (arguments.length < 3) {
+ throw new Error("Function concat expects (string, string[, string]*)");
+ }
+ var s = "";
+ for (var i = 1; i < arguments.length; i++) {
+ s += arguments[i].evaluate(c).stringValue();
+ }
+ return new XString(s);
+};
+
+Functions.startsWith = function() {
+ var c = arguments[0];
+ if (arguments.length != 3) {
+ throw new Error("Function startsWith expects (string, string)");
+ }
+ var s1 = arguments[1].evaluate(c).stringValue();
+ var s2 = arguments[2].evaluate(c).stringValue();
+ return new XBoolean(s1.substring(0, s2.length) == s2);
+};
+
+Functions.contains = function() {
+ var c = arguments[0];
+ if (arguments.length != 3) {
+ throw new Error("Function contains expects (string, string)");
+ }
+ var s1 = arguments[1].evaluate(c).stringValue();
+ var s2 = arguments[2].evaluate(c).stringValue();
+ return new XBoolean(s1.indexOf(s2) !== -1);
+};
+
+Functions.substringBefore = function() {
+ var c = arguments[0];
+ if (arguments.length != 3) {
+ throw new Error("Function substring-before expects (string, string)");
+ }
+ var s1 = arguments[1].evaluate(c).stringValue();
+ var s2 = arguments[2].evaluate(c).stringValue();
+ return new XString(s1.substring(0, s1.indexOf(s2)));
+};
+
+Functions.substringAfter = function() {
+ var c = arguments[0];
+ if (arguments.length != 3) {
+ throw new Error("Function substring-after expects (string, string)");
+ }
+ var s1 = arguments[1].evaluate(c).stringValue();
+ var s2 = arguments[2].evaluate(c).stringValue();
+ if (s2.length == 0) {
+ return new XString(s1);
+ }
+ var i = s1.indexOf(s2);
+ if (i == -1) {
+ return new XString("");
+ }
+ return new XString(s1.substring(i + s2.length));
+};
+
+Functions.substring = function() {
+ var c = arguments[0];
+ if (!(arguments.length == 3 || arguments.length == 4)) {
+ throw new Error("Function substring expects (string, number, number?)");
+ }
+ var s = arguments[1].evaluate(c).stringValue();
+ var n1 = Math.round(arguments[2].evaluate(c).numberValue()) - 1;
+ var n2 = arguments.length == 4 ? n1 + Math.round(arguments[3].evaluate(c).numberValue()) : undefined;
+ return new XString(s.substring(n1, n2));
+};
+
+Functions.stringLength = function() {
+ var c = arguments[0];
+ var s;
+ if (arguments.length == 1) {
+ s = XNodeSet.prototype.stringForNode(c.contextNode);
+ } else if (arguments.length == 2) {
+ s = arguments[1].evaluate(c).stringValue();
+ } else {
+ throw new Error("Function string-length expects (string?)");
+ }
+ return new XNumber(s.length);
+};
+
+Functions.normalizeSpace = function() {
+ var c = arguments[0];
+ var s;
+ if (arguments.length == 1) {
+ s = XNodeSet.prototype.stringForNode(c.contextNode);
+ } else if (arguments.length == 2) {
+ s = arguments[1].evaluate(c).stringValue();
+ } else {
+ throw new Error("Function normalize-space expects (string?)");
+ }
+ var i = 0;
+ var j = s.length - 1;
+ while (Utilities.isSpace(s.charCodeAt(j))) {
+ j--;
+ }
+ var t = "";
+ while (i <= j && Utilities.isSpace(s.charCodeAt(i))) {
+ i++;
+ }
+ while (i <= j) {
+ if (Utilities.isSpace(s.charCodeAt(i))) {
+ t += " ";
+ while (i <= j && Utilities.isSpace(s.charCodeAt(i))) {
+ i++;
+ }
+ } else {
+ t += s.charAt(i);
+ i++;
+ }
+ }
+ return new XString(t);
+};
+
+Functions.translate = function(c, eValue, eFrom, eTo) {
+ if (arguments.length != 4) {
+ throw new Error("Function translate expects (string, string, string)");
+ }
+
+ var value = eValue.evaluate(c).stringValue();
+ var from = eFrom.evaluate(c).stringValue();
+ var to = eTo.evaluate(c).stringValue();
+
+ var cMap = reduce(function (acc, ch, i) {
+ if (!(ch in acc)) {
+ acc[ch] = i > to.length ? '' : to[i];
+ }
+ return acc;
+ }, {}, from);
+
+ var t = join('', map(function (ch) {
+ return ch in cMap ? cMap[ch] : ch;
+ }, value));
+
+ return new XString(t);
+};
+
+Functions.boolean_ = function() {
+ var c = arguments[0];
+ if (arguments.length != 2) {
+ throw new Error("Function boolean expects (object)");
+ }
+ return arguments[1].evaluate(c).bool();
+};
+
+Functions.not = function(c, eValue) {
+ if (arguments.length != 2) {
+ throw new Error("Function not expects (object)");
+ }
+ return eValue.evaluate(c).bool().not();
+};
+
+Functions.true_ = function() {
+ if (arguments.length != 1) {
+ throw new Error("Function true expects ()");
+ }
+ return XBoolean.true_;
+};
+
+Functions.false_ = function() {
+ if (arguments.length != 1) {
+ throw new Error("Function false expects ()");
+ }
+ return XBoolean.false_;
+};
+
+Functions.lang = function() {
+ var c = arguments[0];
+ if (arguments.length != 2) {
+ throw new Error("Function lang expects (string)");
+ }
+ var lang;
+ for (var n = c.contextNode; n != null && n.nodeType != 9 /*Node.DOCUMENT_NODE*/; n = n.parentNode) {
+ var a = n.getAttributeNS(XPath.XML_NAMESPACE_URI, "lang");
+ if (a != null) {
+ lang = String(a);
+ break;
+ }
+ }
+ if (lang == null) {
+ return XBoolean.false_;
+ }
+ var s = arguments[1].evaluate(c).stringValue();
+ return new XBoolean(lang.substring(0, s.length) == s
+ && (lang.length == s.length || lang.charAt(s.length) == '-'));
+};
+
+Functions.number = function() {
+ var c = arguments[0];
+ if (!(arguments.length == 1 || arguments.length == 2)) {
+ throw new Error("Function number expects (object?)");
+ }
+ if (arguments.length == 1) {
+ return new XNumber(XNodeSet.prototype.stringForNode(c.contextNode));
+ }
+ return arguments[1].evaluate(c).number();
+};
+
+Functions.sum = function() {
+ var c = arguments[0];
+ var ns;
+ if (arguments.length != 2 || !Utilities.instance_of((ns = arguments[1].evaluate(c)), XNodeSet)) {
+ throw new Error("Function sum expects (node-set)");
+ }
+ ns = ns.toUnsortedArray();
+ var n = 0;
+ for (var i = 0; i < ns.length; i++) {
+ n += new XNumber(XNodeSet.prototype.stringForNode(ns[i])).numberValue();
+ }
+ return new XNumber(n);
+};
+
+Functions.floor = function() {
+ var c = arguments[0];
+ if (arguments.length != 2) {
+ throw new Error("Function floor expects (number)");
+ }
+ return new XNumber(Math.floor(arguments[1].evaluate(c).numberValue()));
+};
+
+Functions.ceiling = function() {
+ var c = arguments[0];
+ if (arguments.length != 2) {
+ throw new Error("Function ceiling expects (number)");
+ }
+ return new XNumber(Math.ceil(arguments[1].evaluate(c).numberValue()));
+};
+
+Functions.round = function() {
+ var c = arguments[0];
+ if (arguments.length != 2) {
+ throw new Error("Function round expects (number)");
+ }
+ return new XNumber(Math.round(arguments[1].evaluate(c).numberValue()));
+};
+
+// Utilities /////////////////////////////////////////////////////////////////
+
+var Utilities = new Object();
+
+Utilities.isAttribute = function (val) {
+ return val && (val.nodeType === 2 || val.ownerElement);
+}
+
+Utilities.splitQName = function(qn) {
+ var i = qn.indexOf(":");
+ if (i == -1) {
+ return [ null, qn ];
+ }
+ return [ qn.substring(0, i), qn.substring(i + 1) ];
+};
+
+Utilities.resolveQName = function(qn, nr, n, useDefault) {
+ var parts = Utilities.splitQName(qn);
+ if (parts[0] != null) {
+ parts[0] = nr.getNamespace(parts[0], n);
+ } else {
+ if (useDefault) {
+ parts[0] = nr.getNamespace("", n);
+ if (parts[0] == null) {
+ parts[0] = "";
+ }
+ } else {
+ parts[0] = "";
+ }
+ }
+ return parts;
+};
+
+Utilities.isSpace = function(c) {
+ return c == 0x9 || c == 0xd || c == 0xa || c == 0x20;
+};
+
+Utilities.isLetter = function(c) {
+ return c >= 0x0041 && c <= 0x005A ||
+ c >= 0x0061 && c <= 0x007A ||
+ c >= 0x00C0 && c <= 0x00D6 ||
+ c >= 0x00D8 && c <= 0x00F6 ||
+ c >= 0x00F8 && c <= 0x00FF ||
+ c >= 0x0100 && c <= 0x0131 ||
+ c >= 0x0134 && c <= 0x013E ||
+ c >= 0x0141 && c <= 0x0148 ||
+ c >= 0x014A && c <= 0x017E ||
+ c >= 0x0180 && c <= 0x01C3 ||
+ c >= 0x01CD && c <= 0x01F0 ||
+ c >= 0x01F4 && c <= 0x01F5 ||
+ c >= 0x01FA && c <= 0x0217 ||
+ c >= 0x0250 && c <= 0x02A8 ||
+ c >= 0x02BB && c <= 0x02C1 ||
+ c == 0x0386 ||
+ c >= 0x0388 && c <= 0x038A ||
+ c == 0x038C ||
+ c >= 0x038E && c <= 0x03A1 ||
+ c >= 0x03A3 && c <= 0x03CE ||
+ c >= 0x03D0 && c <= 0x03D6 ||
+ c == 0x03DA ||
+ c == 0x03DC ||
+ c == 0x03DE ||
+ c == 0x03E0 ||
+ c >= 0x03E2 && c <= 0x03F3 ||
+ c >= 0x0401 && c <= 0x040C ||
+ c >= 0x040E && c <= 0x044F ||
+ c >= 0x0451 && c <= 0x045C ||
+ c >= 0x045E && c <= 0x0481 ||
+ c >= 0x0490 && c <= 0x04C4 ||
+ c >= 0x04C7 && c <= 0x04C8 ||
+ c >= 0x04CB && c <= 0x04CC ||
+ c >= 0x04D0 && c <= 0x04EB ||
+ c >= 0x04EE && c <= 0x04F5 ||
+ c >= 0x04F8 && c <= 0x04F9 ||
+ c >= 0x0531 && c <= 0x0556 ||
+ c == 0x0559 ||
+ c >= 0x0561 && c <= 0x0586 ||
+ c >= 0x05D0 && c <= 0x05EA ||
+ c >= 0x05F0 && c <= 0x05F2 ||
+ c >= 0x0621 && c <= 0x063A ||
+ c >= 0x0641 && c <= 0x064A ||
+ c >= 0x0671 && c <= 0x06B7 ||
+ c >= 0x06BA && c <= 0x06BE ||
+ c >= 0x06C0 && c <= 0x06CE ||
+ c >= 0x06D0 && c <= 0x06D3 ||
+ c == 0x06D5 ||
+ c >= 0x06E5 && c <= 0x06E6 ||
+ c >= 0x0905 && c <= 0x0939 ||
+ c == 0x093D ||
+ c >= 0x0958 && c <= 0x0961 ||
+ c >= 0x0985 && c <= 0x098C ||
+ c >= 0x098F && c <= 0x0990 ||
+ c >= 0x0993 && c <= 0x09A8 ||
+ c >= 0x09AA && c <= 0x09B0 ||
+ c == 0x09B2 ||
+ c >= 0x09B6 && c <= 0x09B9 ||
+ c >= 0x09DC && c <= 0x09DD ||
+ c >= 0x09DF && c <= 0x09E1 ||
+ c >= 0x09F0 && c <= 0x09F1 ||
+ c >= 0x0A05 && c <= 0x0A0A ||
+ c >= 0x0A0F && c <= 0x0A10 ||
+ c >= 0x0A13 && c <= 0x0A28 ||
+ c >= 0x0A2A && c <= 0x0A30 ||
+ c >= 0x0A32 && c <= 0x0A33 ||
+ c >= 0x0A35 && c <= 0x0A36 ||
+ c >= 0x0A38 && c <= 0x0A39 ||
+ c >= 0x0A59 && c <= 0x0A5C ||
+ c == 0x0A5E ||
+ c >= 0x0A72 && c <= 0x0A74 ||
+ c >= 0x0A85 && c <= 0x0A8B ||
+ c == 0x0A8D ||
+ c >= 0x0A8F && c <= 0x0A91 ||
+ c >= 0x0A93 && c <= 0x0AA8 ||
+ c >= 0x0AAA && c <= 0x0AB0 ||
+ c >= 0x0AB2 && c <= 0x0AB3 ||
+ c >= 0x0AB5 && c <= 0x0AB9 ||
+ c == 0x0ABD ||
+ c == 0x0AE0 ||
+ c >= 0x0B05 && c <= 0x0B0C ||
+ c >= 0x0B0F && c <= 0x0B10 ||
+ c >= 0x0B13 && c <= 0x0B28 ||
+ c >= 0x0B2A && c <= 0x0B30 ||
+ c >= 0x0B32 && c <= 0x0B33 ||
+ c >= 0x0B36 && c <= 0x0B39 ||
+ c == 0x0B3D ||
+ c >= 0x0B5C && c <= 0x0B5D ||
+ c >= 0x0B5F && c <= 0x0B61 ||
+ c >= 0x0B85 && c <= 0x0B8A ||
+ c >= 0x0B8E && c <= 0x0B90 ||
+ c >= 0x0B92 && c <= 0x0B95 ||
+ c >= 0x0B99 && c <= 0x0B9A ||
+ c == 0x0B9C ||
+ c >= 0x0B9E && c <= 0x0B9F ||
+ c >= 0x0BA3 && c <= 0x0BA4 ||
+ c >= 0x0BA8 && c <= 0x0BAA ||
+ c >= 0x0BAE && c <= 0x0BB5 ||
+ c >= 0x0BB7 && c <= 0x0BB9 ||
+ c >= 0x0C05 && c <= 0x0C0C ||
+ c >= 0x0C0E && c <= 0x0C10 ||
+ c >= 0x0C12 && c <= 0x0C28 ||
+ c >= 0x0C2A && c <= 0x0C33 ||
+ c >= 0x0C35 && c <= 0x0C39 ||
+ c >= 0x0C60 && c <= 0x0C61 ||
+ c >= 0x0C85 && c <= 0x0C8C ||
+ c >= 0x0C8E && c <= 0x0C90 ||
+ c >= 0x0C92 && c <= 0x0CA8 ||
+ c >= 0x0CAA && c <= 0x0CB3 ||
+ c >= 0x0CB5 && c <= 0x0CB9 ||
+ c == 0x0CDE ||
+ c >= 0x0CE0 && c <= 0x0CE1 ||
+ c >= 0x0D05 && c <= 0x0D0C ||
+ c >= 0x0D0E && c <= 0x0D10 ||
+ c >= 0x0D12 && c <= 0x0D28 ||
+ c >= 0x0D2A && c <= 0x0D39 ||
+ c >= 0x0D60 && c <= 0x0D61 ||
+ c >= 0x0E01 && c <= 0x0E2E ||
+ c == 0x0E30 ||
+ c >= 0x0E32 && c <= 0x0E33 ||
+ c >= 0x0E40 && c <= 0x0E45 ||
+ c >= 0x0E81 && c <= 0x0E82 ||
+ c == 0x0E84 ||
+ c >= 0x0E87 && c <= 0x0E88 ||
+ c == 0x0E8A ||
+ c == 0x0E8D ||
+ c >= 0x0E94 && c <= 0x0E97 ||
+ c >= 0x0E99 && c <= 0x0E9F ||
+ c >= 0x0EA1 && c <= 0x0EA3 ||
+ c == 0x0EA5 ||
+ c == 0x0EA7 ||
+ c >= 0x0EAA && c <= 0x0EAB ||
+ c >= 0x0EAD && c <= 0x0EAE ||
+ c == 0x0EB0 ||
+ c >= 0x0EB2 && c <= 0x0EB3 ||
+ c == 0x0EBD ||
+ c >= 0x0EC0 && c <= 0x0EC4 ||
+ c >= 0x0F40 && c <= 0x0F47 ||
+ c >= 0x0F49 && c <= 0x0F69 ||
+ c >= 0x10A0 && c <= 0x10C5 ||
+ c >= 0x10D0 && c <= 0x10F6 ||
+ c == 0x1100 ||
+ c >= 0x1102 && c <= 0x1103 ||
+ c >= 0x1105 && c <= 0x1107 ||
+ c == 0x1109 ||
+ c >= 0x110B && c <= 0x110C ||
+ c >= 0x110E && c <= 0x1112 ||
+ c == 0x113C ||
+ c == 0x113E ||
+ c == 0x1140 ||
+ c == 0x114C ||
+ c == 0x114E ||
+ c == 0x1150 ||
+ c >= 0x1154 && c <= 0x1155 ||
+ c == 0x1159 ||
+ c >= 0x115F && c <= 0x1161 ||
+ c == 0x1163 ||
+ c == 0x1165 ||
+ c == 0x1167 ||
+ c == 0x1169 ||
+ c >= 0x116D && c <= 0x116E ||
+ c >= 0x1172 && c <= 0x1173 ||
+ c == 0x1175 ||
+ c == 0x119E ||
+ c == 0x11A8 ||
+ c == 0x11AB ||
+ c >= 0x11AE && c <= 0x11AF ||
+ c >= 0x11B7 && c <= 0x11B8 ||
+ c == 0x11BA ||
+ c >= 0x11BC && c <= 0x11C2 ||
+ c == 0x11EB ||
+ c == 0x11F0 ||
+ c == 0x11F9 ||
+ c >= 0x1E00 && c <= 0x1E9B ||
+ c >= 0x1EA0 && c <= 0x1EF9 ||
+ c >= 0x1F00 && c <= 0x1F15 ||
+ c >= 0x1F18 && c <= 0x1F1D ||
+ c >= 0x1F20 && c <= 0x1F45 ||
+ c >= 0x1F48 && c <= 0x1F4D ||
+ c >= 0x1F50 && c <= 0x1F57 ||
+ c == 0x1F59 ||
+ c == 0x1F5B ||
+ c == 0x1F5D ||
+ c >= 0x1F5F && c <= 0x1F7D ||
+ c >= 0x1F80 && c <= 0x1FB4 ||
+ c >= 0x1FB6 && c <= 0x1FBC ||
+ c == 0x1FBE ||
+ c >= 0x1FC2 && c <= 0x1FC4 ||
+ c >= 0x1FC6 && c <= 0x1FCC ||
+ c >= 0x1FD0 && c <= 0x1FD3 ||
+ c >= 0x1FD6 && c <= 0x1FDB ||
+ c >= 0x1FE0 && c <= 0x1FEC ||
+ c >= 0x1FF2 && c <= 0x1FF4 ||
+ c >= 0x1FF6 && c <= 0x1FFC ||
+ c == 0x2126 ||
+ c >= 0x212A && c <= 0x212B ||
+ c == 0x212E ||
+ c >= 0x2180 && c <= 0x2182 ||
+ c >= 0x3041 && c <= 0x3094 ||
+ c >= 0x30A1 && c <= 0x30FA ||
+ c >= 0x3105 && c <= 0x312C ||
+ c >= 0xAC00 && c <= 0xD7A3 ||
+ c >= 0x4E00 && c <= 0x9FA5 ||
+ c == 0x3007 ||
+ c >= 0x3021 && c <= 0x3029;
+};
+
+Utilities.isNCNameChar = function(c) {
+ return c >= 0x0030 && c <= 0x0039
+ || c >= 0x0660 && c <= 0x0669
+ || c >= 0x06F0 && c <= 0x06F9
+ || c >= 0x0966 && c <= 0x096F
+ || c >= 0x09E6 && c <= 0x09EF
+ || c >= 0x0A66 && c <= 0x0A6F
+ || c >= 0x0AE6 && c <= 0x0AEF
+ || c >= 0x0B66 && c <= 0x0B6F
+ || c >= 0x0BE7 && c <= 0x0BEF
+ || c >= 0x0C66 && c <= 0x0C6F
+ || c >= 0x0CE6 && c <= 0x0CEF
+ || c >= 0x0D66 && c <= 0x0D6F
+ || c >= 0x0E50 && c <= 0x0E59
+ || c >= 0x0ED0 && c <= 0x0ED9
+ || c >= 0x0F20 && c <= 0x0F29
+ || c == 0x002E
+ || c == 0x002D
+ || c == 0x005F
+ || Utilities.isLetter(c)
+ || c >= 0x0300 && c <= 0x0345
+ || c >= 0x0360 && c <= 0x0361
+ || c >= 0x0483 && c <= 0x0486
+ || c >= 0x0591 && c <= 0x05A1
+ || c >= 0x05A3 && c <= 0x05B9
+ || c >= 0x05BB && c <= 0x05BD
+ || c == 0x05BF
+ || c >= 0x05C1 && c <= 0x05C2
+ || c == 0x05C4
+ || c >= 0x064B && c <= 0x0652
+ || c == 0x0670
+ || c >= 0x06D6 && c <= 0x06DC
+ || c >= 0x06DD && c <= 0x06DF
+ || c >= 0x06E0 && c <= 0x06E4
+ || c >= 0x06E7 && c <= 0x06E8
+ || c >= 0x06EA && c <= 0x06ED
+ || c >= 0x0901 && c <= 0x0903
+ || c == 0x093C
+ || c >= 0x093E && c <= 0x094C
+ || c == 0x094D
+ || c >= 0x0951 && c <= 0x0954
+ || c >= 0x0962 && c <= 0x0963
+ || c >= 0x0981 && c <= 0x0983
+ || c == 0x09BC
+ || c == 0x09BE
+ || c == 0x09BF
+ || c >= 0x09C0 && c <= 0x09C4
+ || c >= 0x09C7 && c <= 0x09C8
+ || c >= 0x09CB && c <= 0x09CD
+ || c == 0x09D7
+ || c >= 0x09E2 && c <= 0x09E3
+ || c == 0x0A02
+ || c == 0x0A3C
+ || c == 0x0A3E
+ || c == 0x0A3F
+ || c >= 0x0A40 && c <= 0x0A42
+ || c >= 0x0A47 && c <= 0x0A48
+ || c >= 0x0A4B && c <= 0x0A4D
+ || c >= 0x0A70 && c <= 0x0A71
+ || c >= 0x0A81 && c <= 0x0A83
+ || c == 0x0ABC
+ || c >= 0x0ABE && c <= 0x0AC5
+ || c >= 0x0AC7 && c <= 0x0AC9
+ || c >= 0x0ACB && c <= 0x0ACD
+ || c >= 0x0B01 && c <= 0x0B03
+ || c == 0x0B3C
+ || c >= 0x0B3E && c <= 0x0B43
+ || c >= 0x0B47 && c <= 0x0B48
+ || c >= 0x0B4B && c <= 0x0B4D
+ || c >= 0x0B56 && c <= 0x0B57
+ || c >= 0x0B82 && c <= 0x0B83
+ || c >= 0x0BBE && c <= 0x0BC2
+ || c >= 0x0BC6 && c <= 0x0BC8
+ || c >= 0x0BCA && c <= 0x0BCD
+ || c == 0x0BD7
+ || c >= 0x0C01 && c <= 0x0C03
+ || c >= 0x0C3E && c <= 0x0C44
+ || c >= 0x0C46 && c <= 0x0C48
+ || c >= 0x0C4A && c <= 0x0C4D
+ || c >= 0x0C55 && c <= 0x0C56
+ || c >= 0x0C82 && c <= 0x0C83
+ || c >= 0x0CBE && c <= 0x0CC4
+ || c >= 0x0CC6 && c <= 0x0CC8
+ || c >= 0x0CCA && c <= 0x0CCD
+ || c >= 0x0CD5 && c <= 0x0CD6
+ || c >= 0x0D02 && c <= 0x0D03
+ || c >= 0x0D3E && c <= 0x0D43
+ || c >= 0x0D46 && c <= 0x0D48
+ || c >= 0x0D4A && c <= 0x0D4D
+ || c == 0x0D57
+ || c == 0x0E31
+ || c >= 0x0E34 && c <= 0x0E3A
+ || c >= 0x0E47 && c <= 0x0E4E
+ || c == 0x0EB1
+ || c >= 0x0EB4 && c <= 0x0EB9
+ || c >= 0x0EBB && c <= 0x0EBC
+ || c >= 0x0EC8 && c <= 0x0ECD
+ || c >= 0x0F18 && c <= 0x0F19
+ || c == 0x0F35
+ || c == 0x0F37
+ || c == 0x0F39
+ || c == 0x0F3E
+ || c == 0x0F3F
+ || c >= 0x0F71 && c <= 0x0F84
+ || c >= 0x0F86 && c <= 0x0F8B
+ || c >= 0x0F90 && c <= 0x0F95
+ || c == 0x0F97
+ || c >= 0x0F99 && c <= 0x0FAD
+ || c >= 0x0FB1 && c <= 0x0FB7
+ || c == 0x0FB9
+ || c >= 0x20D0 && c <= 0x20DC
+ || c == 0x20E1
+ || c >= 0x302A && c <= 0x302F
+ || c == 0x3099
+ || c == 0x309A
+ || c == 0x00B7
+ || c == 0x02D0
+ || c == 0x02D1
+ || c == 0x0387
+ || c == 0x0640
+ || c == 0x0E46
+ || c == 0x0EC6
+ || c == 0x3005
+ || c >= 0x3031 && c <= 0x3035
+ || c >= 0x309D && c <= 0x309E
+ || c >= 0x30FC && c <= 0x30FE;
+};
+
+Utilities.coalesceText = function(n) {
+ for (var m = n.firstChild; m != null; m = m.nextSibling) {
+ if (m.nodeType == 3 /*Node.TEXT_NODE*/ || m.nodeType == 4 /*Node.CDATA_SECTION_NODE*/) {
+ var s = m.nodeValue;
+ var first = m;
+ m = m.nextSibling;
+ while (m != null && (m.nodeType == 3 /*Node.TEXT_NODE*/ || m.nodeType == 4 /*Node.CDATA_SECTION_NODE*/)) {
+ s += m.nodeValue;
+ var del = m;
+ m = m.nextSibling;
+ del.parentNode.removeChild(del);
+ }
+ if (first.nodeType == 4 /*Node.CDATA_SECTION_NODE*/) {
+ var p = first.parentNode;
+ if (first.nextSibling == null) {
+ p.removeChild(first);
+ p.appendChild(p.ownerDocument.createTextNode(s));
+ } else {
+ var next = first.nextSibling;
+ p.removeChild(first);
+ p.insertBefore(p.ownerDocument.createTextNode(s), next);
+ }
+ } else {
+ first.nodeValue = s;
+ }
+ if (m == null) {
+ break;
+ }
+ } else if (m.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+ Utilities.coalesceText(m);
+ }
+ }
+};
+
+Utilities.instance_of = function(o, c) {
+ while (o != null) {
+ if (o.constructor === c) {
+ return true;
+ }
+ if (o === Object) {
+ return false;
+ }
+ o = o.constructor.superclass;
+ }
+ return false;
+};
+
+Utilities.getElementById = function(n, id) {
+ // Note that this does not check the DTD to check for actual
+ // attributes of type ID, so this may be a bit wrong.
+ if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+ if (n.getAttribute("id") == id
+ || n.getAttributeNS(null, "id") == id) {
+ return n;
+ }
+ }
+ for (var m = n.firstChild; m != null; m = m.nextSibling) {
+ var res = Utilities.getElementById(m, id);
+ if (res != null) {
+ return res;
+ }
+ }
+ return null;
+};
+
+// XPathException ////////////////////////////////////////////////////////////
+
+var XPathException = (function () {
+ function getMessage(code, exception) {
+ var msg = exception ? ": " + exception.toString() : "";
+ switch (code) {
+ case XPathException.INVALID_EXPRESSION_ERR:
+ return "Invalid expression" + msg;
+ case XPathException.TYPE_ERR:
+ return "Type error" + msg;
+ }
+ return null;
+ }
+
+ function XPathException(code, error, message) {
+ var err = Error.call(this, getMessage(code, error) || message);
+
+ err.code = code;
+ err.exception = error;
+
+ return err;
+ }
+
+ XPathException.prototype = Object.create(Error.prototype);
+ XPathException.prototype.constructor = XPathException;
+ XPathException.superclass = Error;
+
+ XPathException.prototype.toString = function() {
+ return this.message;
+ };
+
+ XPathException.fromMessage = function(message, error) {
+ return new XPathException(null, error, message);
+ };
+
+ XPathException.INVALID_EXPRESSION_ERR = 51;
+ XPathException.TYPE_ERR = 52;
+
+ return XPathException;
+})();
+
+// XPathExpression ///////////////////////////////////////////////////////////
+
+XPathExpression.prototype = {};
+XPathExpression.prototype.constructor = XPathExpression;
+XPathExpression.superclass = Object.prototype;
+
+function XPathExpression(e, r, p) {
+ this.xpath = p.parse(e);
+ this.context = new XPathContext();
+ this.context.namespaceResolver = new XPathNSResolverWrapper(r);
+}
+
+XPathExpression.getOwnerDocument = function (n) {
+ return n.nodeType === 9 /*Node.DOCUMENT_NODE*/ ? n : n.ownerDocument;
+}
+
+XPathExpression.detectHtmlDom = function (n) {
+ if (!n) { return false; }
+
+ var doc = XPathExpression.getOwnerDocument(n);
+
+ try {
+ return doc.implementation.hasFeature("HTML", "2.0");
+ } catch (e) {
+ return true;
+ }
+}
+
+XPathExpression.prototype.evaluate = function(n, t, res) {
+ this.context.expressionContextNode = n;
+ // backward compatibility - no reliable way to detect whether the DOM is HTML, but
+ // this library has been using this method up until now, so we will continue to use it
+ // ONLY when using an XPathExpression
+ this.context.caseInsensitive = XPathExpression.detectHtmlDom(n);
+
+ var result = this.xpath.evaluate(this.context);
+ return new XPathResult(result, t);
+}
+
+// XPathNSResolverWrapper ////////////////////////////////////////////////////
+
+XPathNSResolverWrapper.prototype = {};
+XPathNSResolverWrapper.prototype.constructor = XPathNSResolverWrapper;
+XPathNSResolverWrapper.superclass = Object.prototype;
+
+function XPathNSResolverWrapper(r) {
+ this.xpathNSResolver = r;
+}
+
+XPathNSResolverWrapper.prototype.getNamespace = function(prefix, n) {
+ if (this.xpathNSResolver == null) {
+ return null;
+ }
+ return this.xpathNSResolver.lookupNamespaceURI(prefix);
+};
+
+// NodeXPathNSResolver ///////////////////////////////////////////////////////
+
+NodeXPathNSResolver.prototype = {};
+NodeXPathNSResolver.prototype.constructor = NodeXPathNSResolver;
+NodeXPathNSResolver.superclass = Object.prototype;
+
+function NodeXPathNSResolver(n) {
+ this.node = n;
+ this.namespaceResolver = new NamespaceResolver();
+}
+
+NodeXPathNSResolver.prototype.lookupNamespaceURI = function(prefix) {
+ return this.namespaceResolver.getNamespace(prefix, this.node);
+};
+
+// XPathResult ///////////////////////////////////////////////////////////////
+
+XPathResult.prototype = {};
+XPathResult.prototype.constructor = XPathResult;
+XPathResult.superclass = Object.prototype;
+
+function XPathResult(v, t) {
+ if (t == XPathResult.ANY_TYPE) {
+ if (v.constructor === XString) {
+ t = XPathResult.STRING_TYPE;
+ } else if (v.constructor === XNumber) {
+ t = XPathResult.NUMBER_TYPE;
+ } else if (v.constructor === XBoolean) {
+ t = XPathResult.BOOLEAN_TYPE;
+ } else if (v.constructor === XNodeSet) {
+ t = XPathResult.UNORDERED_NODE_ITERATOR_TYPE;
+ }
+ }
+ this.resultType = t;
+ switch (t) {
+ case XPathResult.NUMBER_TYPE:
+ this.numberValue = v.numberValue();
+ return;
+ case XPathResult.STRING_TYPE:
+ this.stringValue = v.stringValue();
+ return;
+ case XPathResult.BOOLEAN_TYPE:
+ this.booleanValue = v.booleanValue();
+ return;
+ case XPathResult.ANY_UNORDERED_NODE_TYPE:
+ case XPathResult.FIRST_ORDERED_NODE_TYPE:
+ if (v.constructor === XNodeSet) {
+ this.singleNodeValue = v.first();
+ return;
+ }
+ break;
+ case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
+ case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
+ if (v.constructor === XNodeSet) {
+ this.invalidIteratorState = false;
+ this.nodes = v.toArray();
+ this.iteratorIndex = 0;
+ return;
+ }
+ break;
+ case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
+ case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
+ if (v.constructor === XNodeSet) {
+ this.nodes = v.toArray();
+ this.snapshotLength = this.nodes.length;
+ return;
+ }
+ break;
+ }
+ throw new XPathException(XPathException.TYPE_ERR);
+};
+
+XPathResult.prototype.iterateNext = function() {
+ if (this.resultType != XPathResult.UNORDERED_NODE_ITERATOR_TYPE
+ && this.resultType != XPathResult.ORDERED_NODE_ITERATOR_TYPE) {
+ throw new XPathException(XPathException.TYPE_ERR);
+ }
+ return this.nodes[this.iteratorIndex++];
+};
+
+XPathResult.prototype.snapshotItem = function(i) {
+ if (this.resultType != XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE
+ && this.resultType != XPathResult.ORDERED_NODE_SNAPSHOT_TYPE) {
+ throw new XPathException(XPathException.TYPE_ERR);
+ }
+ return this.nodes[i];
+};
+
+XPathResult.ANY_TYPE = 0;
+XPathResult.NUMBER_TYPE = 1;
+XPathResult.STRING_TYPE = 2;
+XPathResult.BOOLEAN_TYPE = 3;
+XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
+XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
+XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE = 6;
+XPathResult.ORDERED_NODE_SNAPSHOT_TYPE = 7;
+XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
+XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
+
+// DOM 3 XPath support ///////////////////////////////////////////////////////
+
+function installDOM3XPathSupport(doc, p) {
+ doc.createExpression = function(e, r) {
+ try {
+ return new XPathExpression(e, r, p);
+ } catch (e) {
+ throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, e);
+ }
+ };
+ doc.createNSResolver = function(n) {
+ return new NodeXPathNSResolver(n);
+ };
+ doc.evaluate = function(e, cn, r, t, res) {
+ if (t < 0 || t > 9) {
+ throw { code: 0, toString: function() { return "Request type not supported"; } };
+ }
+ return doc.createExpression(e, r, p).evaluate(cn, t, res);
+ };
+};
+
+// ---------------------------------------------------------------------------
+
+// Install DOM 3 XPath support for the current document.
+try {
+ var shouldInstall = true;
+ try {
+ if (document.implementation
+ && document.implementation.hasFeature
+ && document.implementation.hasFeature("XPath", null)) {
+ shouldInstall = false;
+ }
+ } catch (e) {
+ }
+ if (shouldInstall) {
+ installDOM3XPathSupport(document, new XPathParser());
+ }
+} catch (e) {
+}
+
+// ---------------------------------------------------------------------------
+// exports for node.js
+
+installDOM3XPathSupport(exports, new XPathParser());
+
+(function() {
+ var parser = new XPathParser();
+
+ var defaultNSResolver = new NamespaceResolver();
+ var defaultFunctionResolver = new FunctionResolver();
+ var defaultVariableResolver = new VariableResolver();
+
+ function makeNSResolverFromFunction(func) {
+ return {
+ getNamespace: function (prefix, node) {
+ var ns = func(prefix, node);
+
+ return ns || defaultNSResolver.getNamespace(prefix, node);
+ }
+ };
+ }
+
+ function makeNSResolverFromObject(obj) {
+ return makeNSResolverFromFunction(obj.getNamespace.bind(obj));
+ }
+
+ function makeNSResolverFromMap(map) {
+ return makeNSResolverFromFunction(function (prefix) {
+ return map[prefix];
+ });
+ }
+
+ function makeNSResolver(resolver) {
+ if (resolver && typeof resolver.getNamespace === "function") {
+ return makeNSResolverFromObject(resolver);
+ }
+
+ if (typeof resolver === "function") {
+ return makeNSResolverFromFunction(resolver);
+ }
+
+ // assume prefix -> uri mapping
+ if (typeof resolver === "object") {
+ return makeNSResolverFromMap(resolver);
+ }
+
+ return defaultNSResolver;
+ }
+
+ /** Converts native JavaScript types to their XPath library equivalent */
+ function convertValue(value) {
+ if (value === null ||
+ typeof value === "undefined" ||
+ value instanceof XString ||
+ value instanceof XBoolean ||
+ value instanceof XNumber ||
+ value instanceof XNodeSet) {
+ return value;
+ }
+
+ switch (typeof value) {
+ case "string": return new XString(value);
+ case "boolean": return new XBoolean(value);
+ case "number": return new XNumber(value);
+ }
+
+ // assume node(s)
+ var ns = new XNodeSet();
+ ns.addArray([].concat(value));
+ return ns;
+ }
+
+ function makeEvaluator(func) {
+ return function (context) {
+ var args = Array.prototype.slice.call(arguments, 1).map(function (arg) {
+ return arg.evaluate(context);
+ });
+ var result = func.apply(this, [].concat(context, args));
+ return convertValue(result);
+ };
+ }
+
+ function makeFunctionResolverFromFunction(func) {
+ return {
+ getFunction: function (name, namespace) {
+ var found = func(name, namespace);
+ if (found) {
+ return makeEvaluator(found);
+ }
+ return defaultFunctionResolver.getFunction(name, namespace);
+ }
+ };
+ }
+
+ function makeFunctionResolverFromObject(obj) {
+ return makeFunctionResolverFromFunction(obj.getFunction.bind(obj));
+ }
+
+ function makeFunctionResolverFromMap(map) {
+ return makeFunctionResolverFromFunction(function (name) {
+ return map[name];
+ });
+ }
+
+ function makeFunctionResolver(resolver) {
+ if (resolver && typeof resolver.getFunction === "function") {
+ return makeFunctionResolverFromObject(resolver);
+ }
+
+ if (typeof resolver === "function") {
+ return makeFunctionResolverFromFunction(resolver);
+ }
+
+ // assume map
+ if (typeof resolver === "object") {
+ return makeFunctionResolverFromMap(resolver);
+ }
+
+ return defaultFunctionResolver;
+ }
+
+ function makeVariableResolverFromFunction(func) {
+ return {
+ getVariable: function (name, namespace) {
+ var value = func(name, namespace);
+ return convertValue(value);
+ }
+ };
+ }
+
+ function makeVariableResolver(resolver) {
+ if (resolver) {
+ if (typeof resolver.getVariable === "function") {
+ return makeVariableResolverFromFunction(resolver.getVariable.bind(resolver));
+ }
+
+ if (typeof resolver === "function") {
+ return makeVariableResolverFromFunction(resolver);
+ }
+
+ // assume map
+ if (typeof resolver === "object") {
+ return makeVariableResolverFromFunction(function (name) {
+ return resolver[name];
+ });
+ }
+ }
+
+ return defaultVariableResolver;
+ }
+
+ function copyIfPresent(prop, dest, source) {
+ if (prop in source) { dest[prop] = source[prop]; }
+ }
+
+ function makeContext(options) {
+ var context = new XPathContext();
+
+ if (options) {
+ context.namespaceResolver = makeNSResolver(options.namespaces);
+ context.functionResolver = makeFunctionResolver(options.functions);
+ context.variableResolver = makeVariableResolver(options.variables);
+ context.expressionContextNode = options.node;
+ copyIfPresent('allowAnyNamespaceForNoPrefix', context, options);
+ copyIfPresent('isHtml', context, options);
+ } else {
+ context.namespaceResolver = defaultNSResolver;
+ }
+
+ return context;
+ }
+
+ function evaluate(parsedExpression, options) {
+ var context = makeContext(options);
+
+ return parsedExpression.evaluate(context);
+ }
+
+ var evaluatorPrototype = {
+ evaluate: function (options) {
+ return evaluate(this.expression, options);
+ }
+
+ ,evaluateNumber: function (options) {
+ return this.evaluate(options).numberValue();
+ }
+
+ ,evaluateString: function (options) {
+ return this.evaluate(options).stringValue();
+ }
+
+ ,evaluateBoolean: function (options) {
+ return this.evaluate(options).booleanValue();
+ }
+
+ ,evaluateNodeSet: function (options) {
+ return this.evaluate(options).nodeset();
+ }
+
+ ,select: function (options) {
+ return this.evaluateNodeSet(options).toArray()
+ }
+
+ ,select1: function (options) {
+ return this.select(options)[0];
+ }
+ };
+
+ function parse(xpath) {
+ var parsed = parser.parse(xpath);
+
+ return Object.create(evaluatorPrototype, {
+ expression: {
+ value: parsed
+ }
+ });
+ }
+
+ exports.parse = parse;
+})();
+
+exports.XPath = XPath;
+exports.XPathParser = XPathParser;
+exports.XPathResult = XPathResult;
+
+exports.Step = Step;
+exports.NodeTest = NodeTest;
+exports.BarOperation = BarOperation;
+
+exports.NamespaceResolver = NamespaceResolver;
+exports.FunctionResolver = FunctionResolver;
+exports.VariableResolver = VariableResolver;
+
+exports.Utilities = Utilities;
+
+exports.XPathContext = XPathContext;
+exports.XNodeSet = XNodeSet;
+exports.XBoolean = XBoolean;
+exports.XString = XString;
+exports.XNumber = XNumber;
+
+// helper
+exports.select = function(e, doc, single) {
+ return exports.selectWithResolver(e, doc, null, single);
+};
+
+exports.useNamespaces = function(mappings) {
+ var resolver = {
+ mappings: mappings || {},
+ lookupNamespaceURI: function(prefix) {
+ return this.mappings[prefix];
+ }
+ };
+
+ return function(e, doc, single) {
+ return exports.selectWithResolver(e, doc, resolver, single);
+ };
+};
+
+exports.selectWithResolver = function(e, doc, resolver, single) {
+ var expression = new XPathExpression(e, resolver, new XPathParser());
+ var type = XPathResult.ANY_TYPE;
+
+ var result = expression.evaluate(doc, type, null);
+
+ if (result.resultType == XPathResult.STRING_TYPE) {
+ result = result.stringValue;
+ }
+ else if (result.resultType == XPathResult.NUMBER_TYPE) {
+ result = result.numberValue;
+ }
+ else if (result.resultType == XPathResult.BOOLEAN_TYPE) {
+ result = result.booleanValue;
+ }
+ else {
+ result = result.nodes;
+ if (single) {
+ result = result[0];
+ }
+ }
+
+ return result;
+};
+
+exports.select1 = function(e, doc) {
+ return exports.select(e, doc, true);
+};
+
+// end non-node wrapper
+})(xpath);