Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handlers/default-types.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<xsl:text>this.setAttribute("value", "</xsl:text><xsl:call-template name="get-duration-info"><xsl:with-param name="type">prefix</xsl:with-param><xsl:with-param name="pattern" select="$pattern" /></xsl:call-template>".concat(this.value).concat("<xsl:call-template name="get-duration-info"><xsl:with-param name="type">abbreviation</xsl:with-param><xsl:with-param name="pattern" select="$pattern" /></xsl:call-template><xsl:text>")); this.previousElementSibling.textContent = this.value;</xsl:text>
</xsl:when>
<xsl:otherwise> <!-- Use value if otherwise -->
<xsl:text>if (this.value) { this.setAttribute("value", this.value</xsl:text><xsl:if test="$whitespace = 'replace'">.replace(/\s/g, " ")</xsl:if><xsl:if test="$whitespace = 'collapse'">.replace(/\s+/g, " ").trim()</xsl:if><xsl:text>); } else { this.removeAttribute("value"); };</xsl:text>
<xsl:text>if (this.value) { this.setAttribute("value", escapeContent(this.value)</xsl:text><xsl:if test="$whitespace = 'replace'">.replace(/\s/g, " ")</xsl:if><xsl:if test="$whitespace = 'collapse'">.replace(/\s+/g, " ").trim()</xsl:if><xsl:text>); } else { this.removeAttribute("value"); };</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
Expand Down
2 changes: 1 addition & 1 deletion js/html-populators.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//check for input elements existing to handle empty elements
&amp;&amp; o.previousElementSibling.previousElementSibling.querySelector("input, textarea, select")
//check if element has been populated with data from an xml document
&amp;&amp; !o.previousElementSibling.previousElementSibling.querySelector("input, textarea, select").hasAttribute("data-xsd2html2xml-filled")) {
&amp;&amp; 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 &gt; button.remove, span &gt; button.remove")
);
Expand Down
18 changes: 17 additions & 1 deletion js/xml-generators.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -132,6 +132,22 @@
} else if (node.getElementsByTagName("textarea").length != 0) {
return node.getElementsByTagName("textarea")[0].value;
}
};

var characterToXmlSafe = {
"&lt;": "&amp;lt;",
"&gt;": "&amp;gt;",
"&amp;": "&amp;amp;",
"\&quot;": "&amp;quot;",
"&apos;": "&amp;apos;" /* This doesn't seem to work, so turned off in escapeContent function */
};

var escapeContent = function(content)
{
return content.replace(/[&lt;&gt;&amp;&quot;]/g, function(character)
{
return characterToXmlSafe[character];
});
}
</xsl:text>
</xsl:element>
Expand Down