From a44739109bb494a3fd60b2039f584da19ebca541 Mon Sep 17 00:00:00 2001 From: Andrew Cornford Date: Thu, 1 Apr 2021 12:35:56 +0100 Subject: [PATCH 1/5] Fix form not populated with XML if minOccurs=0 --- js/html-populators.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/html-populators.xsl b/js/html-populators.xsl index f02409e..334e3c6 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") ); From 3f0d3ce393b4ea19d12c9e1ec3b1870a71d2ea31 Mon Sep 17 00:00:00 2001 From: Andrew Cornford Date: Thu, 1 Apr 2021 13:50:09 +0100 Subject: [PATCH 2/5] Attribute and element values are now escaped (&, <, >, ") for default types (not date related, file, checkbox or range) --- handlers/default-types.xsl | 2 +- js/xml-generators.xsl | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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/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]; + }); } From e29ab0e6911061d8476e73b109d4d834f47d91af Mon Sep 17 00:00:00 2001 From: Andrew Cornford Date: Wed, 15 Dec 2021 15:30:08 +0000 Subject: [PATCH 3/5] Fixed issue where xs:boolean (checkbox) was always checked (ticked) in a rendered form if schema specifies default="true" even when source xml (from generated from XML, not just schema) specifies false --- js/html-populators.xsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/html-populators.xsl b/js/html-populators.xsl index 334e3c6..9fd2b4d 100644 --- a/js/html-populators.xsl +++ b/js/html-populators.xsl @@ -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 + From c4963b896873c4c66c599373b209a9648ab1078c Mon Sep 17 00:00:00 2001 From: Andrew Cornford Date: Thu, 27 Mar 2025 10:50:55 +0000 Subject: [PATCH 4/5] HTML select elements have an empty, default option if XSD doesn't specify default or fixed value. (Previously this was only the case if use="optional" was specified) --- handlers/enumerations.xsl | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/handlers/enumerations.xsl b/handlers/enumerations.xsl index cabede7..1862096 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 - + - + - + - + From cef3eae2495653f6d336a5cf1e5f917850ea4c58 Mon Sep 17 00:00:00 2001 From: Andrew Cornford Date: Thu, 27 Mar 2025 10:53:50 +0000 Subject: [PATCH 5/5] Fixed comment --- handlers/enumerations.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/enumerations.xsl b/handlers/enumerations.xsl index 1862096..5a60851 100644 --- a/handlers/enumerations.xsl +++ b/handlers/enumerations.xsl @@ -56,7 +56,7 @@ - +