diff --git a/handlers/default-types.xsl b/handlers/default-types.xsl index f288e87..60b7be0 100644 --- a/handlers/default-types.xsl +++ b/handlers/default-types.xsl @@ -86,7 +86,7 @@ this.setAttribute("value", "prefix".concat(this.value).concat("abbreviation")); this.previousElementSibling.textContent = this.value; - if (this.value) { this.setAttribute("value", this.value.replace(/\s/g, " ").replace(/\s+/g, " ").trim()); } else { this.removeAttribute("value"); }; + if (this.value) { this.setAttribute("value", escapeContent(this.value).replace(/\s/g, " ").replace(/\s+/g, " ").trim()); } else { this.removeAttribute("value"); }; diff --git a/handlers/enumerations.xsl b/handlers/enumerations.xsl index cabede7..5a60851 100644 --- a/handlers/enumerations.xsl +++ b/handlers/enumerations.xsl @@ -3,25 +3,25 @@ version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> - + - + - + - + this.childNodes.forEach(function(o) { if (o.nodeType == Node.ELEMENT_NODE) o.removeAttribute("selected"); }); this.children[this.selectedIndex].setAttribute("selected","selected"); - + @@ -33,42 +33,44 @@ required - + disabled - + - + - + multiple - + - - - - - + + + + + + - + - + - + @@ -84,23 +86,23 @@ - + - + - + false - + - + @@ -111,22 +113,22 @@ - + handle-enumerations-forwardee - + - + Reusing loaded namespace documents - + @@ -147,7 +149,7 @@ - + @@ -157,34 +159,34 @@ - + - + - + - + handle-enumerations-forwardee - + - + - + - + diff --git a/js/html-populators.xsl b/js/html-populators.xsl index f02409e..9fd2b4d 100644 --- a/js/html-populators.xsl +++ b/js/html-populators.xsl @@ -36,7 +36,7 @@ //check for input elements existing to handle empty elements && o.previousElementSibling.previousElementSibling.querySelector("input, textarea, select") //check if element has been populated with data from an xml document - && !o.previousElementSibling.previousElementSibling.querySelector("input, textarea, select").hasAttribute("data-xsd2html2xml-filled")) { + && Array.from(o.previousElementSibling.previousElementSibling.querySelectorAll("input, textarea, select")).filter(function(el) {return el.hasAttribute("data-xsd2html2xml-filled")}).length == 0) { clickRemoveButton( o.parentElement.children[0].querySelector("legend > button.remove, span > button.remove") ); @@ -85,6 +85,9 @@ if (element.querySelector("input").getAttribute("data-xsd2html2xml-primitive") === "boolean") { if (value === "true") { element.querySelector("input").setAttribute("checked", "checked"); + } + else if(value === "false" && element.querySelector("input").hasAttribute("checked")) { + element.querySelector("input").removeAttribute("checked"); }; } else { element.querySelector("input").setAttribute("value", value); @@ -205,4 +208,4 @@ - \ No newline at end of file + diff --git a/js/xml-generators.xsl b/js/xml-generators.xsl index e741f16..1a152fc 100644 --- a/js/xml-generators.xsl +++ b/js/xml-generators.xsl @@ -116,7 +116,7 @@ case "gyearmonth": return node.getElementsByTagName("input")[0].getAttribute("value"); default: - return node.getElementsByTagName("input")[0].value; + return escapeContent(node.getElementsByTagName("input")[0].value); } } } else if (node.getElementsByTagName("select").length != 0) { @@ -132,6 +132,22 @@ } else if (node.getElementsByTagName("textarea").length != 0) { return node.getElementsByTagName("textarea")[0].value; } + }; + + var characterToXmlSafe = { + "<": "&lt;", + ">": "&gt;", + "&": "&amp;", + "\"": "&quot;", + "'": "&apos;" /* This doesn't seem to work, so turned off in escapeContent function */ + }; + + var escapeContent = function(content) + { + return content.replace(/[<>&"]/g, function(character) + { + return characterToXmlSafe[character]; + }); }