cda-schematron-validator 1.0.2 → 1.0.3
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/package.json +1 -1
- package/validator.js +20 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cda-schematron-validator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Fork of Eric Wadkins' javascript implementation of schematron testing for C-CDA XML documents. This includes bug fixes and some house keeping.",
|
|
5
5
|
"main": "validator.js",
|
|
6
6
|
"scripts": {
|
package/validator.js
CHANGED
|
@@ -25,7 +25,7 @@ function clearCache() {
|
|
|
25
25
|
parsedMap = Object.create({});
|
|
26
26
|
contextMap = Object.create({});
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
let namespaceMap, patternRuleMap, ruleAssertionMap, xpathSelect;
|
|
29
29
|
function validate(xml, schematron, options = {}) {
|
|
30
30
|
// If not valid xml, it might be a filepath
|
|
31
31
|
// Adding explicit check to make it clear
|
|
@@ -79,13 +79,13 @@ function validate(xml, schematron, options = {}) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// Extract data from parsed schematron object
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
namespaceMap = schematronMap.namespaceMap;
|
|
83
|
+
patternRuleMap = schematronMap.patternRuleMap;
|
|
84
|
+
ruleAssertionMap = schematronMap.ruleAssertionMap;
|
|
85
85
|
|
|
86
86
|
// Create selector object, initialized with namespaces
|
|
87
87
|
// Avoid using 'select' as a variable name as it is overused
|
|
88
|
-
|
|
88
|
+
xpathSelect = xpath.useNamespaces(namespaceMap);
|
|
89
89
|
|
|
90
90
|
let errors = [];
|
|
91
91
|
let warnings = [];
|
|
@@ -103,7 +103,7 @@ function validate(xml, schematron, options = {}) {
|
|
|
103
103
|
let ruleId = rules[i];
|
|
104
104
|
let context = ruleAssertionMap[rules[i]].context;
|
|
105
105
|
let assertionsAndExtensions = ruleAssertionMap[rules[i]].assertionsAndExtensions || [];
|
|
106
|
-
let assertionResults = checkRule(xmlDoc,
|
|
106
|
+
let assertionResults = checkRule(xmlDoc, context, assertionsAndExtensions, options);
|
|
107
107
|
for (let j = 0; j < assertionResults.length; j++) {
|
|
108
108
|
let type = assertionResults[j].type;
|
|
109
109
|
let assertionId = assertionResults[j].assertionId;
|
|
@@ -170,7 +170,7 @@ function validate(xml, schematron, options = {}) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// Take the checkRule function out of validate function, and pass on the variable needed as parameters and options
|
|
173
|
-
function checkRule(xmlDoc,
|
|
173
|
+
function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
|
|
174
174
|
// Context cache
|
|
175
175
|
let includeWarnings = options.includeWarnings === undefined ? true : options.includeWarnings;
|
|
176
176
|
let resourceDir = options.resourceDir || './';
|
|
@@ -222,7 +222,18 @@ function checkRule(xmlDoc, xpathSelect, originalContext, assertionsAndExtensions
|
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
else {
|
|
226
|
+
const extensionRule = assertionsAndExtensions[i].rule;
|
|
227
|
+
if (!extensionRule) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const subAssertionsAndExtensions = ruleAssertionMap[extensionRule] ? ruleAssertionMap[extensionRule].assertionsAndExtensions : null;
|
|
231
|
+
if (!subAssertionsAndExtensions) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const newContext = ruleAssertionMap[extensionRule].context;
|
|
235
|
+
results = results.concat(checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options));
|
|
236
|
+
}
|
|
226
237
|
}
|
|
227
238
|
return results;
|
|
228
|
-
}
|
|
239
|
+
}
|