cda-schematron-validator 1.1.2 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ 'env': {
3
+ 'browser': true,
4
+ 'commonjs': true,
5
+ 'es2021': true
6
+ },
7
+ 'extends': [
8
+ 'google'
9
+ ],
10
+ 'parserOptions': {
11
+ 'ecmaVersion': 'latest'
12
+ },
13
+ 'rules': {
14
+ 'comma-dangle': ['error', 'never'],
15
+ 'linebreak-style': 0,
16
+ 'indent': ['error', 4],
17
+ 'require-jsdoc': 0,
18
+ 'object-curly-spacing': 0,
19
+ 'func-call-spacing': 0,
20
+ 'max-len': [2, {
21
+ 'code': 200,
22
+ 'tabWidth': 4,
23
+ 'ignoreUrls': true,
24
+ 'ignorePattern': 'goog\.(module|require)',
25
+ 'ignoreStrings': true,
26
+ 'ignoreComments': true
27
+ }],
28
+ 'brace-style': ['error', 'stroustrup']
29
+ }
30
+ };
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm test
5
+ eslint . --ext .js --fix
package/.jshintrc CHANGED
@@ -1,4 +1,4 @@
1
- /*jshint :esversion 6 */
1
+ /*jshint :esversion 8 */
2
2
  {
3
3
  // JSHint Default Configuration File (as on JSHint website)
4
4
  // See http://jshint.com/docs/ for more details
@@ -40,7 +40,7 @@
40
40
  "debug": true, // true: Allow debugger statements e.g. browser breakpoints.
41
41
  "eqnull": false, // true: Tolerate use of `== null`
42
42
  "es5": false, // true: Allow ES5 syntax (ex: getters and setters)
43
- "esversion": 6,
43
+ "esversion": 8,
44
44
  "esnext": false, // true: Allow ES.next (ES6) syntax (ex: `const`)
45
45
  "moz": false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
46
46
  // (ex: `for each`, multiple try/catch, function expression...)
@@ -69,7 +69,7 @@
69
69
  "dojo": false, // Dojo Toolkit
70
70
  "jquery": true, // jQuery
71
71
  "mootools": false, // MooTools
72
- "node": false, // Node.js
72
+ "node": true, // Node.js
73
73
  "nonstandard": false, // Widely adopted globals (escape, unescape, etc)
74
74
  "prototypejs": false, // Prototype and Scriptaculous
75
75
  "rhino": false, // Rhino
package/Gruntfile.js CHANGED
@@ -1,31 +1,28 @@
1
1
  // jshint node:true
2
- module.exports = function (grunt) {
2
+ const path = require('path');
3
+ module.exports = function(grunt) {
3
4
  grunt.initConfig({
4
- jshint: {
5
+ jshint: {
5
6
  options: {
6
- jshintrc: '.jshintrc',
7
+ jshintrc: path.resolve(__dirname, '.jshintrc')
7
8
  },
8
9
  files: {
9
- src: ['*.js']},
10
+ src: [path.resolve(__dirname, '*.js')]},
10
11
  gruntfile: {
11
- src: 'Gruntfile.js'
12
+ src: path.resolve(__dirname, 'Gruntfile.js')
12
13
  }
13
14
  },
14
15
  mochaTest: {
15
16
  api: {
17
+ src: [path.resolve(__dirname, 'test/*test*.js')],
16
18
  options: {
17
19
  reporter: 'spec'
18
- },
19
- src: ['test/tests.js']
20
+ }
20
21
  }
21
22
  }
22
23
  });
23
-
24
24
  grunt.loadNpmTasks('grunt-contrib-jshint');
25
25
  grunt.loadNpmTasks('grunt-mocha-test');
26
-
27
26
  grunt.registerTask('default', ['jshint', 'mochaTest']);
28
27
  grunt.registerTask('api', ['mochaTest']);
29
-
30
28
  };
31
-
package/README.md CHANGED
@@ -1,34 +1,79 @@
1
1
  # [cda-schematron-validator](https://github.com/priyaranjan-tokachichu/cda-schematron-validator)
2
+
2
3
  ## Release History
3
- Starting release history with 1.0.7
4
- ### 1.1.1
4
+
5
+ ### 1.1.6
6
+
7
+ - Methods have been moved to js files and relocated to lib directory
8
+ - Introduced a new method called validateFileListAsync which allows to supply an array of xml file content or paths to validate
9
+ - An array of results will be returned from the validateFileListAsync method
10
+ - Test file `test/asyncFileList.test.js` has the example usage
11
+ - Started to make use of Promise.all for async methods
12
+ - Documentation of the methods completed by 40%
13
+
14
+ ### 1.1.5
15
+
16
+ - Major methods have been divided into multiple small methods to avoid redundancy across sync and async methods, and reduce maintenance
17
+
18
+ ### 1.1.4 (Stable Release)
19
+
20
+ - Major deviations from the source repository
21
+
22
+ - By default the warning will be turned off in contrast to the parent repository
23
+
24
+ - To get warnings, users have to explicitly specify the option `includeWarnings` with value boolean `true`
25
+
26
+ - We also deviate from the previous behavior where all the checks for warnings were done at the assertion
27
+ level just before testing the xpath. We now would not even parse the phase with @id="warnings" which should
28
+ improve the performance.
29
+
30
+ - Minor cosmetic changes to the code
31
+
32
+ ### 1.1.1 to 1.1.3
33
+
5
34
  - Only keeping the necessary data in the test files taken from HL7 C-CDA schematron repository to avoid bloating the module
35
+
36
+ - Added pre-commit hooks with husky
37
+
38
+ - Added code standardization with prettier, ESLint, and lint-staged
39
+
6
40
  ### 1.1.0
41
+
7
42
  - Fix the issue with the rule check which was working in the original repository, but not in the fork
8
- - Added HL7 C-CDA schematron file and resource file from https://github.com/HL7/CDA-ccda-2.1/releases/tag/2019JUN
43
+ - Added HL7 C-CDA schematron file and resource file from <https://github.com/HL7/CDA-ccda-2.1/releases/tag/2019JUN>
9
44
  - Added a test case vitalSigns.test.js that tests the resource file and sub assertions
10
- - Used resources https://github.com/jddamore/ccda-samples and https://github.com/HL7/C-CDA-Examples/tree/master/Vital%20Signs to create the test file vitalSigns.xml
45
+ - Used resources <https://github.com/jddamore/ccda-samples> and <https://github.com/HL7/C-CDA-Examples/tree/master/Vital%20Signs> to create the test file vitalSigns.xml
46
+
11
47
  ### 1.0.10
48
+
12
49
  - Fix null context issue associated with assertions within assertions
13
50
  - Skip abstract rules associated with assertions within assertions
51
+
14
52
  ### 1.0.9
53
+
15
54
  - Fixed the bug introduced in 1.0.8 trying to adjust to different data types of the return value
16
55
  - Changed variable names to improve understanding of the process
56
+
17
57
  ### 1.0.8
58
+
18
59
  - Bug fix identifying the ignored errors
60
+
19
61
  ### 1.0.7
62
+
20
63
  - Added async validate function `validateAsync`
21
64
  - Added `testsAsync` to test `validateAsync`
22
65
  - Plan to use common functions between sync and async methods in the future release
23
66
 
24
67
  ### 1.0.0 to 1.0.6
25
- A fork to the original cda-schematron. All credit to Eric Wadkins. Visit the github https://github.com/ewadkins/cda-schematron for the original repo.
68
+
69
+ A fork to the original cda-schematron. All credit to Eric Wadkins. Visit the github <https://github.com/ewadkins/cda-schematron> for the original repo.
26
70
 
27
71
  This is just a cosmetic change with updated node modules, a couple of minor bugs observed, and esversion 6 changes.
28
72
 
29
- The changes are fully backward compatible. So, leaving the original documentation as is below.
73
+ The changes are fully backward compatible. So, leaving the original documentation as is below.
30
74
 
31
75
  ### New option parameter parsedSchematronMap
76
+
32
77
  In addition to everything that was possible,
33
78
  you can now supply a new option parameter `parsedSchematronMap`. You can create a schematron map as follows.
34
79
 
@@ -44,24 +89,25 @@ const options = {
44
89
  };
45
90
  const results = validate('xml string or file path', 'schematron sting, file path or null', options);
46
91
  ```
92
+
47
93
  If a schematron map is provided, the schematron string or path will not be read.
48
94
 
49
95
  To install this npm module, it will be
50
96
 
97
+ ```javascript
98
+ npm i cda-schematron-validator
51
99
  ```
52
- npm install cda-schematron-validator
53
- ```
54
- Mocha VS Code configuratin added to directly execute the test file in `test/tests.js` using VS Code.
55
100
 
101
+ Mocha VS Code configuratin added to directly execute the test file in `test/tests.js` using VS Code.
56
102
 
57
- # Original Documentation of the cda-schematron
58
- ## [cda-schematron](https://github.com/ewadkins/cda-schematron)
103
+ ## Documentation of the parent repo [cda-schematron](https://github.com/ewadkins/cda-schematron)
59
104
 
60
105
  A javascript implementation of schematron testing for XML documents. This specifically resolves a need for a package that allows a quick, reliable install for validating HL7 clinical documents, such as C-CDA.
61
106
 
62
107
  Check out [cda-schematron-server](https://github.com/ewadkins/cda-schematron-server), a server wrapper of **cda-schematron**, for easy schematron validation.
63
108
 
64
109
  ### Validating xml
110
+
65
111
  ```javascript
66
112
  var validator = require('cda-schematron');
67
113
 
@@ -74,21 +120,27 @@ var schematron = fs.readFileSync(schematronPath).toString();
74
120
 
75
121
  var results = validator.validate(xml, schematron);
76
122
  ```
123
+
77
124
  File paths can also be passed to the validator directly. The following lines all return the same results:
125
+
78
126
  ```javascript
79
127
  var results = validator.validate(xml, schematronPath);
80
128
  ```
129
+
81
130
  ```javascript
82
131
  var results = validator.validate(xmlPath, schematron);
83
132
  ```
133
+
84
134
  ```javascript
85
135
  var results = validator.validate(xmlPath, schematronPath);
86
136
  ```
87
137
 
88
138
  ### Results
139
+
89
140
  ```results``` is an object containing arrays ```errors```, ```warnings```, and ```ignoreds```.
90
141
 
91
142
  **Errors** and **warnings** are reported as determined by the schematron and test descriptions. They are of the following form:
143
+
92
144
  ```javascript
93
145
  {
94
146
  type: type, // "error" or "warning"
@@ -106,6 +158,7 @@ var results = validator.validate(xmlPath, schematronPath);
106
158
  ```
107
159
 
108
160
  **Ignored** tests are those that resulted in an exception while running (eg. the test is invalid xpath and could not be parsed properly) and require manual inspection. They are of the following form:
161
+
109
162
  ```javascript
110
163
  {
111
164
  errorMessage: errorMessage, // reason for the exception/ignoring the test
@@ -121,13 +174,14 @@ var results = validator.validate(xmlPath, schematronPath);
121
174
  ```
122
175
 
123
176
  ### Options
177
+
124
178
  The ```validate``` function takes in an ```options``` object as an optional third argument. The three fields that can be included in ```options``` are as follows:
125
179
 
126
- * **```includeWarnings```**: ```true``` or ```false```, this determines whether or not warnings should be tested and returned. Defaults to ```true```.
180
+ - **```includeWarnings```**: ```true``` or ```false```, this determines whether or not warnings should be tested and returned. Defaults to ```true```.
127
181
 
128
- * **```resourceDir```**: the path to a directory containing resource files (eg. voc.xml) which may be necessary for some schematron tests. Defaults to ```'./'```, the current directory.
182
+ - **```resourceDir```**: the path to a directory containing resource files (eg. voc.xml) which may be necessary for some schematron tests. Defaults to ```'./'```, the current directory.
129
183
 
130
- * **```xmlSnippetMaxLength```**: an integer, which is the maximum length of the ```xml``` field in validation results. Defaults to ```200```. Set to ```0``` for unlimited length.
184
+ - **```xmlSnippetMaxLength```**: an integer, which is the maximum length of the ```xml``` field in validation results. Defaults to ```200```. Set to ```0``` for unlimited length.
131
185
 
132
186
  Here is an example with warnings disabled:
133
187
 
@@ -136,12 +190,15 @@ var results = validator.validate(xml, schematron, { includeWarnings: false });
136
190
  ```
137
191
 
138
192
  ### Cache
193
+
139
194
  The validator uses a cache to store parsed schematrons, an intermediate data structure used to store revelant schematron information. This reduces the runtime of the validator when validating against the same schematron multiple times. You can clear the cache at any time with:
195
+
140
196
  ```javascript
141
197
  validator.clearCache();
142
198
  ```
143
199
 
144
200
  ---
201
+
145
202
  ## License (MIT)
146
203
 
147
204
  Copyright &copy; 2017 [Eric Wadkins](http://www.ericwadkins.com/)
@@ -0,0 +1,28 @@
1
+ const fs = require('fs');
2
+ /**
3
+ * @method checkIfFileOrPath Checks if a given xml string is xml content or file path to the xml, and extracts the content and
4
+ * assigns it back to the variable. If no data could be found or there is an issue to access the file, an error will be returned.
5
+ * @param {string} givenString xml string or a path to the xml file (the xml can be an xml file or schematron file which is basically an xml)
6
+ * @returns If it is a valid xml, returns it. If it is a file path, extracts the content and returns it. Otherwise throws appropriate error.
7
+ */
8
+
9
+ function checkIfFileOrPath(givenString) {
10
+ // If not valid xml, it might be a filepath
11
+ // Adding explicit check to make it clear
12
+ if (!givenString) {
13
+ return new Error('No data found in the xml or schematron');
14
+ }
15
+ if (givenString.trim().indexOf('<') === -1) {
16
+ try {
17
+ givenString = fs.readFileSync(givenString, 'utf-8').toString();
18
+ }
19
+ catch (err) {
20
+ // If no valid xml found, inform user, and return immediately
21
+ console.log('No valid xml or schematron could be found');
22
+ return err;
23
+ }
24
+ }
25
+ return givenString;
26
+ }
27
+
28
+ module.exports = checkIfFileOrPath;
@@ -0,0 +1,35 @@
1
+ const getSelectXmlChunk = require('./getSelectXmlChunk');
2
+ const processAssertions = require('./processAssertions');
3
+ // Take the checkRule function out of validate function, and pass on the variable needed as parameters and options
4
+ function checkRule(context, assertionsAndExtensions, options) {
5
+ // Context cache
6
+ const failedAssertions = [];
7
+ // Determine the sections within context, load selected section from cache if possible
8
+ const selectedXml = getSelectXmlChunk(context, options);
9
+ for (let i = 0; i < assertionsAndExtensions.length; i++) {
10
+ const assertionAndExtensionObject = assertionsAndExtensions[i];
11
+ if (assertionAndExtensionObject.type === 'assertion') {
12
+ processAssertions(assertionAndExtensionObject, selectedXml, failedAssertions, options);
13
+ }
14
+ else {
15
+ const failedSubAssertions = processExtension(assertionAndExtensionObject, context, options);
16
+ failedAssertions.push(...failedSubAssertions);
17
+ }
18
+ }
19
+ return failedAssertions;
20
+ }
21
+
22
+ function processExtension(assertionAndExtensionObject, context, options) {
23
+ const extensionRule = assertionAndExtensionObject.rule;
24
+ let failedSubAssertions = [];
25
+ if (extensionRule) {
26
+ const newRuleObject = options.schematronMap.ruleAssertionMap[extensionRule];
27
+ const subAssertionsAndExtensions = newRuleObject ? newRuleObject.assertionsAndExtensions : null;
28
+ if (subAssertionsAndExtensions) {
29
+ failedSubAssertions = checkRule(context, subAssertionsAndExtensions, options);
30
+ }
31
+ }
32
+ return failedSubAssertions;
33
+ }
34
+
35
+ module.exports = checkRule;
@@ -0,0 +1,12 @@
1
+ function getAssertionObject(level, id, originalTest, simplifiedTest, description) {
2
+ const assertionObject = {
3
+ type: level,
4
+ assertionId: id,
5
+ test: originalTest,
6
+ simplifiedTest: simplifiedTest,
7
+ description: description
8
+ };
9
+ return assertionObject;
10
+ }
11
+
12
+ module.exports = getAssertionObject;
@@ -0,0 +1,34 @@
1
+ function getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo) {
2
+ const { type, assertionId, test, simplifiedTest, description, results } = assertionObject;
3
+ const { patternId, ruleId, context } = assertionInfo;
4
+ const { errors, warnings } = resultInfo;
5
+ for (let index = 0; index < results.length; index++) {
6
+ const resultObject = results[index];
7
+ const { result, line, path, xml } = resultObject;
8
+ // If the xpath did not return a result (result=false), then there should be
9
+ // and error or warning
10
+ if (!result) {
11
+ const obj = {
12
+ type,
13
+ test,
14
+ simplifiedTest,
15
+ description,
16
+ line,
17
+ path,
18
+ patternId,
19
+ ruleId,
20
+ assertionId,
21
+ context,
22
+ xml
23
+ };
24
+ if (type === 'error') {
25
+ errors.push(obj);
26
+ }
27
+ else {
28
+ warnings.push(obj);
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ module.exports = getErrorsAndWarnings;
@@ -0,0 +1,16 @@
1
+ const _get = require('lodash.get');
2
+ const checkRule = require('./checkRule');
3
+ function getFailedAssertions(ruleId, assertionInfo, options) {
4
+ let failedAssertions;
5
+ assertionInfo.ruleId = ruleId;
6
+ const ruleObject = options.schematronMap.ruleAssertionMap[ruleId];
7
+ if (!_get(ruleObject, 'abstract')) {
8
+ const context = _get(ruleObject, 'context');
9
+ assertionInfo.context = context;
10
+ const assertionsAndExtensions = _get(ruleObject, 'assertionsAndExtensions') || [];
11
+ failedAssertions = checkRule(context, assertionsAndExtensions, options);
12
+ }
13
+ return failedAssertions;
14
+ }
15
+
16
+ module.exports = getFailedAssertions;
@@ -0,0 +1,19 @@
1
+ function getIgnored(assertionObject, assertionInfo, resultInfo) {
2
+ const { type, assertionId, test, simplifiedTest, description, errorMessage } = assertionObject;
3
+ const { patternId, ruleId, context } = assertionInfo;
4
+ const { ignored } = resultInfo;
5
+ const obj = {
6
+ errorMessage,
7
+ type,
8
+ test,
9
+ simplifiedTest,
10
+ description,
11
+ patternId,
12
+ ruleId,
13
+ assertionId,
14
+ context
15
+ };
16
+ ignored.push(obj);
17
+ }
18
+
19
+ module.exports = getIgnored;
@@ -0,0 +1,13 @@
1
+ const getErrorsAndWarnings = require('./getErrorsAndWarnings');
2
+ const getIgnored = require('./getIgnored');
3
+ function getResults(assertionObject, assertionInfo, resultInfo) {
4
+ const { results } = assertionObject;
5
+ if (Array.isArray(results)) {
6
+ getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo);
7
+ }
8
+ else if (results.ignored) {
9
+ getIgnored(assertionObject, assertionInfo, resultInfo);
10
+ }
11
+ }
12
+
13
+ module.exports = getResults;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @method getReturnObject Simple method to avoid redundancy of result object representation
3
+ * @param {object} resultInfo carrying the arrays errors, warnings and ignored
4
+ * @returns result object with information about overall errors, warnings and ignored
5
+ */
6
+
7
+ function getReturnObject(resultInfo) {
8
+ const { errors, warnings, ignored } = resultInfo;
9
+ const result = {
10
+ errorCount: errors.length,
11
+ warningCount: warnings.length,
12
+ ignoredCount: ignored.length,
13
+ errors: errors,
14
+ warnings: warnings,
15
+ ignored: ignored
16
+ };
17
+ return result;
18
+ }
19
+
20
+ module.exports = getReturnObject;
@@ -0,0 +1,31 @@
1
+ const Dom = require('@xmldom/xmldom').DOMParser;
2
+ const crypto = require('crypto');
3
+ const _get = require('lodash.get');
4
+ const parseSchematron = require('../parseSchematron');
5
+ /**
6
+ * @method getSchematronMap A method to get the schematron map from the provided schematron or utilize the data from cache or options object
7
+ * @param {string} schematron String data of schematron
8
+ * @param {object} options options object passed to `validate` or `validateAsync` method
9
+ * @returns {object} parsed schemtaron map object
10
+ */
11
+
12
+ function getSchematronMap(schematron, options = {}) {
13
+ if (_get(options, 'parsedSchematronMap')) {
14
+ return _get(options, 'parsedSchematronMap');
15
+ }
16
+ const hash = crypto
17
+ .createHash('md5')
18
+ .update(schematron)
19
+ .digest('hex');
20
+ if (options.parsedMap[hash]) {
21
+ return options.parsedMap[hash];
22
+ }
23
+ // If not in cache
24
+ // Load schematron doc
25
+ const schematronDoc = new Dom().parseFromString(schematron);
26
+ // Parse schematron
27
+ options.parsedMap[hash] = parseSchematron(schematronDoc, options);
28
+ return options.parsedMap[hash];
29
+ }
30
+
31
+ module.exports = getSchematronMap;
@@ -0,0 +1,20 @@
1
+ function getSelectXmlChunk(context, options) {
2
+ // Determine the sections within context, load selected section from cache if possible
3
+ let selectedXml = options.contextMap[context];
4
+ let contextModified = context;
5
+ if (!selectedXml) {
6
+ if (context) {
7
+ if (context.indexOf('/')) {
8
+ contextModified = '//' + context;
9
+ }
10
+ selectedXml = options.xpathSelect(contextModified, options.xmlDoc);
11
+ }
12
+ else {
13
+ selectedXml = [options.xmlDoc];
14
+ }
15
+ options.contextMap[context] = selectedXml;
16
+ }
17
+ return selectedXml;
18
+ }
19
+
20
+ module.exports = getSelectXmlChunk;
@@ -4,18 +4,16 @@ module.exports = modifyTest;
4
4
 
5
5
  const fs = require('fs');
6
6
  const xpath = require('xpath');
7
- const dom = require('@xmldom/xmldom').DOMParser;
8
- const path_module = require('path');
7
+ const Dom = require('@xmldom/xmldom').DOMParser;
8
+ const path = require('path');
9
9
 
10
- let loadedExternalDocuments = Object.create({});
10
+ const loadedExternalDocuments = Object.create({});
11
11
 
12
12
  function modifyTest(test, resourceDir) {
13
-
14
13
  let matches = /=document\((\'[-_.A-Za-z0-9]+\'|\"[-_.A-Za-z0-9]+\")\)/.exec(test);
15
14
  while (matches) {
16
-
17
15
  // String processing to select the non-regular predicate expression
18
- let equalInd = test.indexOf(matches[0]);
16
+ const equalInd = test.indexOf(matches[0]);
19
17
  let start = equalInd;
20
18
  let bracketDepth = 0;
21
19
  for (let i = equalInd; i >= 0; i--) {
@@ -30,7 +28,7 @@ function modifyTest(test, resourceDir) {
30
28
  bracketDepth--;
31
29
  }
32
30
  }
33
-
31
+
34
32
  let end = test.length;
35
33
  bracketDepth = 0;
36
34
  for (let i = start + matches[0].length; i < test.length; i++) {
@@ -45,34 +43,34 @@ function modifyTest(test, resourceDir) {
45
43
  bracketDepth--;
46
44
  }
47
45
  }
48
-
49
- let predicate = test.slice(start, end);
50
-
46
+
47
+ const predicate = test.slice(start, end);
48
+
51
49
  // Load external doc (load from "cache" if already loaded)
52
- let filepath = matches[1].slice(1, -1);
50
+ const filepath = matches[1].slice(1, -1);
53
51
  let externalDoc;
54
52
  if (!loadedExternalDocuments[filepath]) {
55
53
  let externalXml = null;
56
54
  try {
57
- externalXml = fs.readFileSync(path_module.join(resourceDir, filepath), 'utf-8').toString();
55
+ externalXml = fs.readFileSync(path.join(resourceDir, filepath), 'utf-8').toString();
58
56
  }
59
57
  catch (err) {
60
58
  throw new Error('No such file \'' + filepath + '\'');
61
59
  }
62
- externalDoc = new dom().parseFromString(externalXml);
60
+ externalDoc = new Dom().parseFromString(externalXml);
63
61
  loadedExternalDocuments[filepath] = externalDoc;
64
62
  }
65
63
  else {
66
64
  externalDoc = loadedExternalDocuments[filepath];
67
65
  }
68
-
69
- let externalXpath = test.slice(equalInd + matches[0].length, end);
70
-
66
+
67
+ const externalXpath = test.slice(equalInd + matches[0].length, end);
68
+
71
69
  // Extract namespaces
72
- let defaultNamespaceKey = /([^(<>.\/)]+):[^(<>.\/)]+/.exec(externalXpath)[1];
73
- let externalNamespaceMap = externalDoc.lastChild._nsMap;
74
- let namespaceMap = {};
75
- for (let key in externalNamespaceMap) {
70
+ const defaultNamespaceKey = /([^(<>.\/)]+):[^(<>.\/)]+/.exec(externalXpath)[1];
71
+ const externalNamespaceMap = externalDoc.lastChild._nsMap;
72
+ const namespaceMap = {};
73
+ for (const key in externalNamespaceMap) {
76
74
  if (externalNamespaceMap.hasOwnProperty(key)) {
77
75
  if (key) {
78
76
  namespaceMap[key] = externalNamespaceMap[key];
@@ -80,16 +78,16 @@ function modifyTest(test, resourceDir) {
80
78
  }
81
79
  }
82
80
  namespaceMap[defaultNamespaceKey] = externalNamespaceMap[''];
83
-
84
- let externalSelect = xpath.useNamespaces(namespaceMap);
85
-
81
+
82
+ const externalSelect = xpath.useNamespaces(namespaceMap);
83
+
86
84
  // Create new predicate from extract values
87
- let values = [];
88
- let externalResults = externalSelect(externalXpath, externalDoc);
85
+ const values = [];
86
+ const externalResults = externalSelect(externalXpath, externalDoc);
89
87
  for (let i = 0; i < externalResults.length; i++) {
90
88
  values.push(externalResults[i].value);
91
89
  }
92
- let lhv = predicate.slice(0, predicate.indexOf('=document('));
90
+ const lhv = predicate.slice(0, predicate.indexOf('=document('));
93
91
  let newPredicate = '(';
94
92
  for (let i = 0; i < values.length; i++) {
95
93
  newPredicate += lhv + '=\'' + values[i] + '\'';
@@ -98,12 +96,12 @@ function modifyTest(test, resourceDir) {
98
96
  }
99
97
  }
100
98
  newPredicate += ')';
101
-
99
+
102
100
  // Replace test
103
101
  test = test.slice(0, start) + newPredicate + test.slice(end);
104
-
102
+
105
103
  matches = /@[^\[\]]+=document\((\'[-_.A-Za-z0-9]+\'|\"[-_.A-Za-z0-9]+\")\)/.exec(test);
106
104
  }
107
-
105
+
108
106
  return test;
109
- }
107
+ }