Skip to content Skip to sidebar Skip to footer

Generate HTML Form From Schematron

is it possible to generate HTML form from a Schematron? I have a bunch of schemas described in Schematron files. I have to create HTML forms which allow to input data which will be

Solution 1:

Very interesting question. It can be done with XSD because XSD describes the structure of valid XML documents (what elements can appear, in what order, how many times, etc.). So an app can just turn around this process and show the user a form allowing to fill input widget elements, reorder elements, etc, that at the end will generate a valid XML document.

However Schematron does not usally describes XML document structure, but rather it give extremlly powerfull semmantic rules or constraints. So (in the general case) the process cannot be reversed to show a form that produces a valid XML document. However it can be done depending on what your Schematrons looks like, but think about this simple example (taken from this page):

<schema xmlns="http://www.ascc.net/xml/schematron" >
     <pattern name="Test integer">
          <rule context="AAA">
               <assert test="floor(.) = number(.)">The AAA value is not an integer.</assert>
          </rule>
     </pattern>
</schema>

There are many different XML document structures that produces XML documents valid against this Schematron, so you may have a form to fill the element value but the Schematron doesn't provides enough information about what the structure of the document should be: where should the element be placed?, how many times should the element appear?, etc.

Source: in my final degree project I built a multiplatform app that given an XSD (and optionally an Schematron, and optionally an XSLT) it generated a form so that any user could create a XML document valid against the XSD and the Schematron, without them needing to know anything about XML/XSD/Schematron/XSLT. The info of the Schematron (if present) was used to do extra validations, and even to dynamically disable enumeration values that if selected will cause Schematron errors. But please note that the info of the Schematron was not enough to know what structure should the XML document have (that info were present in the XSD). In case you want to know, the XSLT document (if present) was used to optionally transform the resulting XML document to other type of document more suitable for the user, like HTML or PDF.


Post a Comment for "Generate HTML Form From Schematron"