Applying a stylesheet in an instance to data in an instance

Hello,

Applying a stylesheet in an instance to data in an instance is not yet 
possible with XForms 2.0 but implementations have extensions for that.

Of course, it's difficult to know what authors would do with this 
feature but it is definitely a powerful yet original approach for XForms 
versus usual Javascript developments.

Have a look at 
http://blackmesatech.com/2012/07/testcase/transform/index.xml !

With Saxon-CE, even XSLT 2.0 is now available at client-side.

There are many possible parameters for an XSLT stylesheet but I think 
that a simplified approach with a transform() function returning text 
and an extra action for XML output, such as loadXML, could do the trick 
just to begin with.

What do you think?

Thanks!

Alain Couthures
agenceXML

-------- Message original --------
Sujet: 	Re: [Xsltforms-support] applying a stylesheet in an instance to 
data in an instance
Date : 	Mon, 16 Jul 2012 10:09:20 +0200
De : 	Alain Couthures <alain.couthures@agencexml.com>
Pour : 	C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
Copie à : 	support xsltforms <xsltforms-support@lists.sourceforge.net>



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?

Thanks!

-Alain

Le 15/07/2012 22:14, C. M. Sperberg-McQueen a écrit :
> On Jul 12, 2012, at 3:15 PM, C. M. Sperberg-McQueen wrote:
>
>> In a form I'm working on, I'd like to apply a stylesheet located in a
>> document instance (instance('filter') to an input document located in
>> another instance (instance('userdoc')).
> For others interested in this topic, I should record that this is in fact
> possible and a simple extension function does the job.
>
> A number of test cases that demonstrate the use of transform() and
> an extension function for instance-based XSLT transforms can be
> found at
>
>    http://blackmesatech.com/2012/07/testcase/transform/index.xml
>
> Michael Sperberg-McQueen
>
>
>> ...
>> So I wrote an extension function that looks like this:
>>
>>       function bmt_applyxslt_ns_s(nsXML, sXSLT) {
>>          if (arguments.length !== 2) {
>>             throw XsltForms_xpathFunctionExceptions.transformInvalidArgumentsNumber;
>>          }
>> 	 return nsXML.length === 0? "" : XsltForms_browser.transformText(XsltForms_browser.saveXML(nsXML[0]), sXSLT, true);
>>       }
>>
>> This is almost verbatim the same as the source code for transform(),
>> except for the argument names and 'true' instead of 'false' in the
>> third argument.
> This code appears to work correctly, given a good stylesheet.
>
>> I register the function with XSLTforms in the usual way.
>>
>>   <xf:setvalue
>>       ref="instance('userout')/self::data"
>>       value="bmt:s_applyxslt_ns_s(instance('userdoc'), serialize(instance('filter')))"/>
>>
>> The form loads as expected and the function seems to be called
>> without incident and without error messages (and alert messages
>> confirm that the arguments look pretty much as I expect them to look).
>> But the result is consistently not the output I expect from the stylesheet,
>> but a document which reads in its entirety:
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
>> <head><title></title></head>
>> <body>
>> <pre></pre>
>> </body>
>> </html>
>>
>> Anyone have a clue?  Anyone have a better (or just different) way to go about
>> this?
> This appears to be Safari's way of signaling an error of some kind in the
> execution of the XSLT transform.
>
>

Received on Monday, 16 July 2012 08:29:14 UTC