Project

Profile

Help

injecting java instances into XSLT

Added by Anonymous about 15 years ago

Legacy ID: #7740904 Legacy Poster: Carlos Delgado (carlosdelgado)

Hi, We're trying to create dynamic web content by applying some XSLT transformations to a particular XML, and then injecting some dynamic variables such as strings and java objects to personalize the content. It would be ideal to be able to inject only string variables, which works fine, but some of our objects are too complex and we need to manipulate them in the XSLT. We have upgraded our saxon lib version from 8 to 9.2 open source. Right now we're trying something like this: XLST: [...] <xsl:param name="answerForm" required="yes" as="jt:com.bmj.learning.flows.QuestionSetAnswers" xmlns:jt="http://saxon.sf.net/java-type&quot;/> [...] <xsl:variable name="is-pre-sel-call"> <xsl:value-of select="QuestionSetAnswers:getQuestion($answerForm)" xmlns:QuestionSetAnswers="java:com.bmj.learning.QuestionSetAnswers" /> </xsl:variable> Java code: final TransformerFactoryImpl factory = new net.sf.saxon.TransformerFactoryImpl(); factory.setAttribute(net.sf.saxon.FeatureKeys.TRACE_EXTERNAL_FUNCTIONS, Boolean.TRUE); final Transformer transformer = factory.newTransformer(new StreamSource("C:/data/webapps/xsltgeneratemodulejsp.xsl")); transformer.setParameter("answerForm", answerForm); But we get a XSL compilation error. Can somebody tell me why can this be happening? And does somebody knows how is the performance affected by injecting string parameters or even java objects to an XSLT transformation? Any help would be much appreciated. Carlos


Replies (3)

Please register to reply

RE: injecting java instances into XSLT - Added by Anonymous about 15 years ago

Legacy ID: #7740918 Legacy Poster: Michael Kay (mhkay)

Saxon Home Edition doesn't support the "reflexive" calling of Java methods as extension functions. For this capability, you'll either have to upgrade to Professional Edition, or stick with Saxon-B (whose last release was 9.1). Or find another way of doing it, such as converting the Java object to XML first, for example by using data binding.

RE: injecting java instances into XSLT - Added by Anonymous about 15 years ago

Legacy ID: #7740947 Legacy Poster: Carlos Delgado (carlosdelgado)

That's great, really helpful. It works now! Re the performance, is there something I should care about? And what is the difference for this specific functionality between 9.1 and 9.2 professional ed? Thanks!

RE: injecting java instances into XSLT - Added by Anonymous about 15 years ago

Legacy ID: #7740965 Legacy Poster: Michael Kay (mhkay)

>Re the performance, is there something I should care about? Well, Java reflection always imposes a cost. Whether that cost is significant in the context of your application is something you can only really establish by measurement. My guess is that it probably isn't. >And what is the difference for this specific functionality between 9.1 and 9.2 professional ed? There are no major changes in this particular area: it's just that 9.2 introduced a repackaging of functionality. This was done to try and ensure that those who were getting most commercial value from the product were feeding back some revenue to enable ongoing development and support.

    (1-3/3)

    Please register to reply