Re: [Xsltforms-support] applying a stylesheet in an instance to data in an instance
Brought to you by:
alain-couthures
From: C. M. Sperberg-M. <cm...@bl...> - 2012-07-16 14:33:04
|
On Jul 16, 2012, at 2:09 AM, Alain Couthures wrote: > The "transform()" function is not yet fully specified and it would be > easy to temporarily add a third parameter to it to switch from URI to text. > > As you mention it in your test case, another situation is whether the > node for the stylesheet is a leaf or a sub-tree to be serialized and a > fourth parameter could indicate this. > > Currently, XSLTForms only supports a text result for the transformation > and it can be used within a "setvalue" action. A sort of "loadXML" > action could easily be added so the result will be loaded as a sub-tree. > > What do you think? For what it's worth, I think it would be useful to have a standard way to load the result of a transform into an instance. In case an example helps, the form I was working on this past week may serve as a simple use case. It involves two XSLT processes: first, the user loads an XML document and a static stylesheet (the 'factory') runs over the user's document and produces a second stylesheet (the 'filter'), and then the user can configure the filter by changing various default behaviors. Whey they are done, they can save the filter to disk or apply the filter to the user's document. Since the point of the filter is to produce untagged text for the user to feed into text analysis or statistical software that does not understand XML (it's sad to think that people still use such software, but I'm told they do), there is no particular need to load the XML structure of the second transformation result into an instance. (Initially I used the 'text' output method in the transform, but all the browsers I tested appear to insist on producing either XML or HTML output from a transform, so I switched to the XML output method and wrapped the text result in an 'output' element.) But the result of the first transformation MUST be loaded into an instance for the form to serve its purpose; the point of the form is to illustrate, for a panel discussion at a conference next week, (a) that it's not enough just to 'strip the tags out' of an XML document and (b) that it's possible to provide an interface to allow an intelligent selection from the encoded document. So the user must be able to edit the filter, which means the filter must be an XML instance. In this case, I handled the lack of 'loadXML' action by using a simple trick: I submit the text result of the initial transformation to a script on the server, which does nothing but bounce it back to the client as text/xml. The submission is defined this way: <xf:submission id="load-userxslt" ref="instance('filter')/text()" method="post" resource="../../../lib/reflect-as-xml.sh" replace="instance" instance="filter" /> The 'filter' instance initially contains the text-node output from the transformation; this submission sends that output (without the outermost wrapper element, which is not needed) to the server, where 'reflect-as-xml.sh' does nothing but send it back with an HTTP header. Reduced to its essentials, reflect-as-xml.sh looks like this: #!/bin/sh echo "Content-Type: text/xml" echo cat It would be a nicer solution, however, if no server round-trip were required here. (I thought about trying to figure out how to do that in Javascript with an extension function or extension action, but I decided to go with this quicker solution, for purposes of the demo.) In case it's of interest to readers of this list, the form in question is now visible at http://blackmesatech.com/2012/07/dh/sdb.xml The form is intended as a toy to illustrate some general principles, and not as a tool for really serious work. (So in particular, don't give it a very large document to work with. It works fine on a TEI-encoded sonnet, and it takes several minutes [and counting] to handle one of Shakespeare's five-act plays.) -- **************************************************************** * C. M. Sperberg-McQueen, Black Mesa Technologies LLC * http://www.blackmesatech.com * http://cmsmcq.com/mib * http://balisage.net **************************************************************** |