Skip to content

Commit

Permalink
Fixed some processor-specific incompatibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
MichielCM committed Feb 19, 2018
1 parent f357425 commit 0f004f4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 35 deletions.
13 changes: 5 additions & 8 deletions xsd+xml2html.xsl
Expand Up @@ -24,10 +24,10 @@

<xsl:strip-space elements="*"/>

<!-- set method as either html or xhtml. Note: if you want to process the results
<!-- set method as either html or xhtml (xml). Note: if you want to process the results
with html2xml.xsl, you need to use xhtml. Note 2: browsers won't display the form correctly if
it does not contain a valid XHTML doctype and if it is not served with content type application/xhtml+xml -->
<!-- <xsl:output method="xhtml" omit-xml-declaration="no" indent="no" /> -->
<!-- <xsl:output method="xml" omit-xml-declaration="no" indent="no" /> -->
<xsl:output method="html" omit-xml-declaration="yes" indent="no" />

<!-- choose the JavaScript (js) or XSLT (xslt) option for processing the form results -->
Expand Down Expand Up @@ -500,8 +500,6 @@
<xsl:param name="disabled">false</xsl:param> <!-- is used to disable elements that are copies for additional occurrences -->
<xsl:param name="tree" /> <!-- contains an XPath query relative to the current node, to be used with 'xml-doc' -->

<xsl:variable name="ref" select="@ref" />

<xsl:variable name="namespace-documents">
<!-- <xsl:call-template name="get-my-namespace-documents" /> -->
<xsl:call-template name="get-namespace-documents">
Expand All @@ -519,7 +517,7 @@

<xsl:variable name="ref-suffix">
<xsl:call-template name="get-suffix">
<xsl:with-param name="string" select="$ref" />
<xsl:with-param name="string" select="@ref" />
</xsl:call-template>
</xsl:variable>

Expand Down Expand Up @@ -551,7 +549,7 @@
<xsl:with-param name="include-colon">true</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="simple" select="false" />
<xsl:with-param name="simple">false</xsl:with-param>
<xsl:with-param name="choice" select="$choice"/>
<xsl:with-param name="disabled" select="$disabled" />
<xsl:with-param name="tree" select="$tree" />
Expand Down Expand Up @@ -583,7 +581,7 @@

<xsl:variable name="ref-suffix">
<xsl:call-template name="get-suffix">
<xsl:with-param name="string" select="$ref" />
<xsl:with-param name="string" select="@ref" />
</xsl:call-template>
</xsl:variable>

Expand Down Expand Up @@ -1485,7 +1483,6 @@
</xsl:when>
<!-- use fixed attribute as data if specified -->
<xsl:when test="@fixed">
<!--<xsl:attribute name="readonly">readonly</xsl:attribute>-->
<xsl:choose>
<xsl:when test="$type = 'xs:boolean'">
<xsl:if test="@fixed = 'true'">
Expand Down
112 changes: 89 additions & 23 deletions xsd2html.xsl
Expand Up @@ -24,10 +24,10 @@

<xsl:strip-space elements="*"/>

<!-- set method as either html or xhtml. Note: if you want to process the results
<!-- set method as either html or xhtml (xml). Note: if you want to process the results
with html2xml.xsl, you need to use xhtml. Note 2: browsers won't display the form correctly if
it does not contain a valid XHTML doctype and if it is not served with content type application/xhtml+xml -->
<!-- <xsl:output method="xhtml" omit-xml-declaration="no" /> -->
<!-- <xsl:output method="xml" omit-xml-declaration="no" /> -->
<xsl:output method="html" omit-xml-declaration="yes" indent="no" />

<!-- choose the JavaScript (js) or XSLT (xslt) option for processing the form results -->
Expand Down Expand Up @@ -191,24 +191,31 @@
}

var clickRemoveButton = function(button) {
if ((button.parentNode.parentNode.parentNode.children.length - 2) == button.parentNode.parentNode.parentNode.lastElementChild.getAttribute("data-xsd2html2xml-min"))
button.parentNode.parentNode.parentNode.lastElementChild.click();
if ((button.closest("section").children.length - 2) == button.closest("section").lastElementChild.getAttribute("data-xsd2html2xml-min"))
button.closest("section").lastElementChild.click();

if ((button.parentNode.parentNode.parentNode.children.length - 2) == button.parentNode.parentNode.parentNode.lastElementChild.getAttribute("data-xsd2html2xml-max"))
button.parentNode.parentNode.parentNode.lastElementChild.removeAttribute("disabled");
if ((button.closest("section").children.length - 2) == button.closest("section").lastElementChild.getAttribute("data-xsd2html2xml-max"))
button.closest("section").lastElementChild.removeAttribute("disabled");

button.parentNode.parentNode.parentNode.removeChild(
button.parentNode.parentNode
button.closest("section").removeChild(
button.closest("fieldset, label")
);
}

var clickRadioInput = function(input, name) {
document.querySelectorAll("[name=" + name + "]").forEach(function(o) {
document.querySelectorAll("[name=".concat(name).concat("]")).forEach(function(o) {
o.removeAttribute("checked");
o.parentElement.nextElementSibling.querySelectorAll("input, select, textarea").forEach(function(p) {
if (input.parentElement.nextElementSibling.contains(p))
p.removeAttribute("disabled");
else
var section = o.parentElement.nextElementSibling;

section.querySelectorAll("input, select, textarea").forEach(function(p) {
if (input.parentElement.nextElementSibling.contains(p)) {
if (p.closest("[data-xsd2html2xml-choice]") === section) {
if (p.closest("*[style]") === null)
p.removeAttribute("disabled");
else
p.setAttribute("disabled", "disabled");
}
} else
p.setAttribute("disabled", "disabled");
});
});
Expand Down Expand Up @@ -407,7 +414,7 @@
<xsl:with-param name="disabled" select="$disabled" />
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($type, 'xs:')">
<xsl:when test="substring-before($type, ':') = 'xs'">
<xsl:call-template name="handle-simple-elements">
<xsl:with-param name="choice" select="$choice"/>
<xsl:with-param name="disabled" select="$disabled" />
Expand All @@ -428,14 +435,27 @@
</xsl:call-template>
</xsl:template>

<!-- handles elements referencing other elements -->
<xsl:template match="xs:element[@ref]|xs:attribute[@ref]">
<xsl:param name="choice" /> <!-- handles xs:choice elements and descendants; contains a unique ID for radio buttons of the same group to share -->
<xsl:param name="disabled">false</xsl:param> <!-- is used to disable elements that are copies for additional occurrences -->

<xsl:variable name="ref" select="@ref" />

<xsl:apply-templates select="//*[@name=$ref]">
<xsl:with-param name="choice" select="$choice"/>
<xsl:with-param name="disabled" select="$disabled" />
</xsl:apply-templates>
</xsl:template>

<!-- handles groups existing of other elements; note that 'ref' is used as id overriding local-name() -->
<xsl:template match="xs:group[@ref]">
<xsl:param name="choice" /> <!-- handles xs:choice elements and descendants; contains a unique ID for radio buttons of the same group to share -->
<xsl:param name="disabled">false</xsl:param> <!-- is used to disable elements that are copies for additional occurrences -->

<xsl:call-template name="handle-complex-elements">
<xsl:with-param name="id" select="@ref" />
<xsl:with-param name="simple" select="false" />
<xsl:with-param name="simple">false</xsl:with-param>
<xsl:with-param name="choice" select="$choice"/>
<xsl:with-param name="disabled" select="$disabled" />
</xsl:call-template>
Expand All @@ -446,6 +466,7 @@
<xsl:param name="disabled">false</xsl:param> <!-- is used to disable elements that are copies for additional occurrences -->

<xsl:variable name="ref" select="@ref" />

<xsl:apply-templates select="//xs:attributeGroup[@name=$ref]/xs:attribute">
<xsl:with-param name="id" select="@ref" />
<xsl:with-param name="disabled" select="$disabled" />
Expand All @@ -467,6 +488,7 @@
<xsl:with-param name="description">
<xsl:call-template name="get-description" />
</xsl:with-param>
<xsl:with-param name="disabled" select="$disabled" />
</xsl:call-template>
</xsl:if>

Expand Down Expand Up @@ -551,6 +573,13 @@
|xs:complexType/xs:choice
|xs:complexType/xs:attribute
|xs:complexType/xs:attributeGroup
|xs:complexType/xs:complexContent/xs:restriction/xs:sequence
|xs:complexType/xs:complexContent/xs:restriction/xs:all
|xs:complexType/xs:complexContent/xs:restriction/xs:choice
|xs:complexType/xs:complexContent/xs:restriction/xs:attribute
|xs:complexType/xs:complexContent/xs:restriction/xs:attributeGroup
|xs:complexType/xs:simpleContent/xs:restriction/xs:attribute
|xs:complexType/xs:simpleContent/xs:restriction/xs:attributeGroup
|//xs:group[@name=$ref]/*">
<xsl:with-param name="disabled" select="$disabled" />
</xsl:apply-templates>
Expand Down Expand Up @@ -613,6 +642,7 @@
<xsl:with-param name="description">
<xsl:call-template name="get-description" />
</xsl:with-param>
<xsl:with-param name="disabled" select="$disabled" />
</xsl:call-template>
</xsl:if>

Expand Down Expand Up @@ -647,7 +677,7 @@
</xsl:with-param>
<xsl:with-param name="static">false</xsl:with-param>
<xsl:with-param name="count">1</xsl:with-param>
<xsl:with-param name="invisible" select="'true'" />
<xsl:with-param name="invisible">true</xsl:with-param>
<xsl:with-param name="disabled">true</xsl:with-param>
</xsl:call-template>

Expand Down Expand Up @@ -789,6 +819,11 @@
</xsl:otherwise>
</xsl:choose>

<!-- disabled elements are used to omit invisible placeholders from inclusion in the validation and generated xml data -->
<xsl:if test="$disabled = 'true'">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>

<!-- add options for each value; populate the element if there is corresponding data, or fill it with a fixed or default value -->
<xsl:call-template name="handle-enumerations">
<xsl:with-param name="default">
Expand Down Expand Up @@ -971,10 +1006,13 @@
<xsl:value-of select="$type" />
</xsl:attribute>

<xsl:if test="@fixed">
<xsl:attribute name="readonly">readonly</xsl:attribute>
</xsl:if>

<xsl:choose>
<!-- use fixed attribute as data if specified -->
<xsl:when test="@fixed">
<xsl:attribute name="readonly">readonly</xsl:attribute>
<xsl:choose>
<xsl:when test="$type = 'xs:boolean'">
<xsl:if test="@fixed = 'true'">
Expand Down Expand Up @@ -1138,22 +1176,42 @@

<!-- Returns an element's description from xs:annotation/xs:documentation if it exists, @value in the case of enumerations, or @name otherwise -->
<xsl:template name="get-description">
<xsl:variable name="documentation">
<xsl:call-template name="get-documentation" />
</xsl:variable>

<xsl:choose>
<xsl:when test="$documentation = ''">
<xsl:choose>
<xsl:when test="@name">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:when test="@value">
<xsl:value-of select="@value" />
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$documentation" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Returns an element's description from xs:annotation/xs:documentation if it exists, taking into account the specified preferred language -->
<xsl:template name="get-documentation">
<xsl:choose>
<xsl:when test="not($config-language = '') and xs:annotation/xs:documentation[@xml:lang=$config-language]">
<xsl:value-of select="xs:annotation/xs:documentation[@xml:lang=$config-language]/text()" />
</xsl:when>
<xsl:when test="not($config-language = '') and xs:annotation/xs:documentation[not(@xml:lang)]">
<xsl:value-of select="xs:annotation/xs:documentation[not(@xml:lang)]/text()" />
</xsl:when>
<xsl:when test="$config-language = '' and xs:annotation/xs:documentation[not(@xml:lang)]">
<xsl:value-of select="xs:annotation/xs:documentation[not(@xml:lang)]/text()" />
</xsl:when>
<xsl:when test="$config-language = '' and xs:annotation/xs:documentation">
<xsl:value-of select="xs:annotation/xs:documentation/text()" />
</xsl:when>
<xsl:when test="@name">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:when test="@value">
<xsl:value-of select="@value" />
</xsl:when>
</xsl:choose>
</xsl:template>

Expand Down Expand Up @@ -1218,6 +1276,9 @@
<xsl:when test="xs:union/@memberTypes">
<xsl:value-of select="xs:simpleType/xs:union/@memberTypes"/>
</xsl:when>
<xsl:when test="@ref">
<xsl:value-of select="@ref"/> <!-- a @ref attribute does not contain a type but an element reference. It does contain the prefix of the namespace where the element's type is declared, so it is required to look up the element specification -->
</xsl:when>
</xsl:choose>
</xsl:template>

Expand Down Expand Up @@ -1318,6 +1379,7 @@
<xsl:template name="add-choice-button">
<xsl:param name="name" />
<xsl:param name="description" />
<xsl:param name="disabled">false</xsl:param>

<xsl:element name="label">
<xsl:if test="not($config-label-after-input = 'true')">
Expand All @@ -1331,6 +1393,10 @@
<xsl:attribute name="name">
<xsl:value-of select="$name"/>
</xsl:attribute>
<xsl:attribute name="required">required</xsl:attribute>
<xsl:if test="$disabled = 'true'">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>
<xsl:attribute name="onclick">clickRadioInput(this, '<xsl:value-of select="$name" />');</xsl:attribute>
</xsl:element>

Expand Down
8 changes: 4 additions & 4 deletions xsd2html2xml.xsl
Expand Up @@ -5,15 +5,15 @@
<xsl:import href="xsd+xml2html.xsl" />
<!--<xsl:import href="xsd2html.xsl" />-->

<!-- set method as either html or xhtml. Note: if you want to process the results
<!-- set method as either html or xhtml (xml). Note: if you want to process the results
with html2xml.xsl, you need to use xhtml. Note 2: browsers won't display the form correctly if
it does not contain a valid XHTML doctype and if it is not served with content type application/xhtml+xml -->
<!-- <xsl:output method="xhtml" omit-xml-declaration="no" indent="no" /> -->
<!-- <xsl:output method="xml" omit-xml-declaration="no" indent="no" /> -->
<xsl:output method="html" omit-xml-declaration="yes" indent="no" />

<!-- optionally specify the xml document to populate the form with -->
<xsl:variable name="xml-doc">
<xsl:copy-of select="document('complex-sample.xml')/*"/>
<xsl:copy-of select="document('{XMLDOC}')/*"/>
</xsl:variable>

<!-- choose the JavaScript (js) or XSLT (xslt) option for processing the form results -->
Expand All @@ -34,7 +34,7 @@
<xsl:variable name="config-label-after-input">true</xsl:variable>

<!-- optionally specify which annotation/documentation language (determined by xml:lang) should be used -->
<xsl:variable name="config-language">nl</xsl:variable>
<xsl:variable name="config-language">en</xsl:variable>

<!-- optionally specify text for interactive elements -->
<xsl:variable name="config-add-button-label">+</xsl:variable>
Expand Down

0 comments on commit 0f004f4

Please sign in to comment.