Subject: [xsl] best way to generate form from xml+schema? From: Graham Seaman <graham@xxxxxxxxx> Date: Fri, 12 Oct 2001 18:07:03 +0100 (BST) |
Hi, This is a query about what the best approach is to an xsl task, rather than a specific syntax query. I'm using xsl to generate html forms from xml files, so that the data in those files can be changed. The xml structure is defined in a schema rather than a dtd. I have to drive the form generation from the schema rather than the xml file, since there are many optional fields which may be defined in the schema but not used in any particular xml file. I've found that I can easily generate a blank form from the schema (expanding extensions, refs etc) in quite a generic way that doesn't break with minor changes in the schema. The problems come when I try to fill in the form data from the xml file. I have a working solution, which I don't like: read in the xml file using document(), then at the leaves of the schema use name() in an XPath expression on the xml node-set to match the name of the xml leaf against that of the schema leaf, and so fetch the right data. The problem with this is that it forces me to make all xml leaf names unique (for example, I originally had <submitter><name>x</name><email>a@xxx</email></submitter> <translator><name>y</name><email>f@xxx</email></translator> as part of the xml; I've now been forced to change <name> to <submitterName> and <translatorName> respectively, which seems to lose part of the point of using xml in the first place. As an alternative, I've tried to match the leaf ancestor names as well as the actual leaf names. This allows me to have identical names at the leaves, but makes the XPath expressions horribly complex and much more fragile, in the sense that small changes in the xml definition require changes to the xsl. The only other alternative I could think of was to replace all <xsl:apply-template>s with <xsl:call-template>s, and pass the node-set from the xsl file as a parameter to each template, stripping off the upper levels as I descend through the tree. But this doesn't seem in keeping with the spirit of xsl, quite apart from the problem that I couldn't handle the syntax! I'm sure I can't be the only person doing this - it must be a pretty standard thing to do. Could anyone point me at examples? Or suggest a better way that I've missed? Thanks Graham XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Sorting outside of a for-, Thomas B. Passin | Thread | Re: [xsl] best way to generate form, Jeni Tennison |
RE: [xsl] Problem with document() f, Michael Kay | Date | [xsl] extracting part of an attribu, Jennifer Wrightsell |
Month |