doXslTransform() in BPELSE
I've been meaning to blog about this for weeks, but BPELSE now has support for the function "doXslTransform". Why am I, Mr. XsltSE, blogging about BPEL? I've alluded to in previous blog entries, and will now confirm, I was part of the BPELSE team for a while last year and one of my many (fascinating and absolutely critical) contributions was implementing this particular function. So this blog is not only to announce (again, to a stunningly large audience) the inclusion of this feature but also walk through what it does and how to use it.
First, for those of you who've not spent countless hours reading the BPEL spec (which is hopefully most of you), the purpose of the doXslTransform() function is to account for BPEL's inability to perform complex XML transformation via its <copy> construct. By providing the means for a user to embed an externally defined XSL stylesheet inside the process, these complex transformations can be specified in a portable fashion. But so far, I'm just paraphrasing the spec, specifically the latter part of section 8.4; let's look at the function signature in detail.
object bpel:doXslTransform(file-name, node-set, (param-name, param-value)*) |
The first parameter specifies the URI of the XSL stylesheet to apply and MUST be a string literal. The second parameter is the data to be transformed and is expected to be a single element ( "an XPath node set... [containing] a single EII" ). The additional parameters represent xsl:param values passed to the XSL stylesheet and are a little trickier: they MUST be specified in name-value pairs. To put it another way, if your stylesheet has a global xsl:param declaration, the only way to specify a value is to pass in two additional parameters to doXslTransform(). The first is the name of the param, which MUST match the name attribute in the xsl:param, and the second is the value, which can be an XPath expression. For a little more information about xsl parameters, please take a gander at this reference.
There is tooling for this feature, but there are currently some minor issues (which bug 112503 is tracking). The functoid is there and can be dragged onto the mapper canvas, which will get the function declared in your BPEL. But there are no fields for the additional parameters yet, so you'll have to specify them manually. Also, the mapper allows you to drag non-string-literals into the stylesheet field, which won't work at all. As always, I urge you to go give it a test spin and see how much more robust your business process can be. In the interest of full disclosure, this particular BPEL feature makes XsltSE technically unnecessary (i.e. each Transform activity in a transformation process is functionally equivalent to an Assign activity using doXslTransform() in a business process). That said, transformation processes are still a simpler alternative to BPEL and will (hopefully) provide functionality and an ease of use that will encourage their use. Otherwise I'm back on BPELSE this time next year (likely wearing a dunce cap)... Thanks for reading!

Hi Kevan,
Interesting text. I tried doXslTransform, works fine. However, I found it slower (5x) comparing with standard Java transformation code. Also increased memory footprint.
What is the reason for that?
Thanks,
Aleks
Posted by Aleksandar Milenovic on January 23, 2008 at 05:12 AM PST #
Hi Aleks,
There are a few things going on other than the transformation:
- doXslTransform() is implemented as a JXPath extension function, meaning it must be resolved by a JXPath evaluation context at runtime.
- The stylesheet must be loaded from the deployed XSL file and compiled before a javax.xml.transform.Transformer can be created.
- Each parameter must be evaluated by the JXPath context to have a value to pass in to the standard Java transformation code (i.e. Transformer.setParameter)
- Lastly, the input is transformed.
Please remember these transformations are not occurring in a vacuum; rather they occur within the context of the BPEL engine and, in this case, the JXPath libraries on which we rely. Hope that helps!
Regards,
Kevan
Posted by Kevan Simpson on January 23, 2008 at 10:58 AM PST #