-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615462a
commit 821a610
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ScriptOK = ({ xslText }) => { | ||
if (xslText === '') { | ||
return null; | ||
} | ||
|
||
const parser = new DOMParser(); | ||
const xsltProcessor = new XSLTProcessor(); | ||
|
||
console.log('xslText =', xslText); | ||
const xslStylesheet = parser.parseFromString(xslText, 'application/xml'); | ||
const errorNode = xslStylesheet.querySelector('parsererror'); | ||
if (errorNode) { | ||
let errorMessage = errorNode.textContent; | ||
console.log('untrimmed =', errorMessage); | ||
errorMessage = errorMessage.trim(); | ||
console.log('trimmed =', errorMessage); | ||
// This is often of the form: | ||
// XML Parsing Error: syntax error Location: http://localhost:3000/settings/ha/step/10010?layer=edit Line Number 1, Column 1 | ||
errorMessage = errorMessage.replace(/Location: https?:[^ ]+/, ''); | ||
return 'Bad XML: ' + errorMessage; | ||
} | ||
|
||
console.log('xslStylesheet =', xslStylesheet); | ||
try { | ||
xsltProcessor.importStylesheet(xslStylesheet); | ||
} catch (e) { | ||
// No value to the exception: it's effectively a boolean (thrown or not) | ||
// The XML was not valid XSLT | ||
return 'Bad XSLT'; | ||
} | ||
return 'Good XSLT'; | ||
}; | ||
|
||
ScriptOK.propTypes = { | ||
xslText: PropTypes.string, | ||
}; | ||
|
||
export default ScriptOK; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters