Generate HTML form from Schematron

廉价感情. 提交于 2019-12-12 10:06:02

问题


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 transformed into an XML documents compatible with Schematrons. Instead of a manual development of forms I would like to generate them in any way. Is it possible? Do you know tools for this?

I found similar tools for generating HTML forms from XSD, for example https://github.com/davidmoten/xsd-forms .


回答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.



来源:https://stackoverflow.com/questions/41761837/generate-html-form-from-schematron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!