[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] best way to generate form from xml+schema?


Subject: Re: [xsl] best way to generate form from xml+schema?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 16 Oct 2001 11:55:27 +0100

Hi Graham,

> I originally wanted to use xsl as far as possible, with perl just as
> a 'glue' language completely independent of the particular schema
> used. But I'm starting to wonder how practical that actually is
> (especially without the ability to use XML1.1 style variables). I've
> just started realising the problems in coming back in the reverse
> direction ie. once the form has been submitted, I need to take the
> incoming cgi parameters and match them against the schema to
> generate the new xml file. At the moment, the only idea I have for
> that is to give the cgi parameters names which reflect the xml
> structure (eg not 'email', but 'programItem:submitter:email'). Write
> the parameters to a temporary file. Then use a stylesheet heavily
> dependent on 'substring-after' functions to generate an xml file
> with expanded versions of the parameters
> (eg
> <programItem>
>         <submitter>
>                 <email>a@xxx</email>
>         </submitter>
> </programItem> 
> Then read this into a second stylesheet which also reads in the
> schema to generate the full xml file.

You might want to look at the XForms method of achieving a similar
kind of thing. There, the basic approach is to link each input field
to a location in some template XML, using an XPath. What I'm
suggesting is, if you know what the XML document will look like as a
whole (or can construct a sample from the schema, which isn't *too*
difficult), then you can basically copy that, using the result of the
form to populate the elements and attributes with values. I think that
would be easier than trying to parse strings to create an XML
document, especially when some of the paths overlap each other
(although I have no doubt it's *possible* to approach it in that way).

> I'm assuming there's no way to do this more directly with only
> xsl1.0 variables... (eg. I can't pack the incoming parameters to a
> stylesheet into a variable and access them using 'name()' matched
> against the schema). It's starting to look like the number of file
> writes and reads may make this method too slow to be very practical
> compared with doing everything in Perl.

I don't think you should be shy about using a node-set() extension
function to get the XML variables that you want. Virtually every XSLT
processor in existence has one, so the stylesheet needn't be
completely unportable, if you're worried about that.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords