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

Re: [xsl] Call java function to do background work

Subject: Re: [xsl] Call java function to do background work
From: Ming Yu <my600080@xxxxxxxxx>
Date: Tue, 19 Jun 2012 08:17:33 -0700 (PDT)

Thanks a lot! I am actually using xsl:result-document when I need to generate
multiple output files from one source file. But I'm not using it when it's
one-to-one scenario. The variable I'm appending to from my background function
call is for sure being used. In this case, I can make sure that the background
function call will be executed.

Again, thanks for the help.


Original Message -----
From: Michael Kay <mike@xxxxxxxxxxxx>
Sent: Tuesday, June 12, 2012 1:10 PM
Subject: Re: [xsl] Call java function to do background work

It's not a good
idea to do something involving side-effects while evaluating a variable,
because optimizers tend to assume that evaluating a variable is something they
can do as and when and as often as they please. If the variable isn't used,
it's very likely that it will never be evaluated; if two variables are
involved, it's unpredictable which order they will be evaluated in. In some
cases an optimizer might decide to evaluate a variable repeatedly rather than
allocating memory to hold its value.

It might not seem an obvious approach,
but my suggestion would be to do this using xsl:result-document. That's about
the closest XSLT gets to an instruction designed to have side effects, and
there are rules about its behaviour designed to limit the damage that
optimizers can do. There's still no absolute rule ensuring the order in which
different result documents are generated (in recent Saxon releases, you can
create lots of result documents in parallel), but at least there's a
reasonable chance that each one will be written exactly once.

In Saxon
there's a mechanism (the OutputURIResolver) that allows the Java application
to intercept calls to xsl:result-document. So by encapsulating the information
needed by the application within the URI given to the result document (or
putting it within the document itself) you can use xsl:result-document as a
way of saying "here's some information, please process it in the background".
Michael Kay

On 12/06/2012 16:07, Ming Yu wrote:
> Sorry if this is a
very simple question but I couldn't seem to come up with a neat solution.
During xslt transformation, I need to call a java function to do some
background work (such as adding some values to the database, etc). The java
function doesn't need to return anything. At this moment, I just use the
normail<xsl:value-of>  tag to append to a variable. Since it doesn't return
anything, the variable value stays the same.
> Is there a neater to achieve
this goal?
> Thanks a lot!
> Ming
XSL-List info and archive:http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to:http://lists.mulberrytech.com/xsl-list/
> or
> --~--

Current Thread