0

I'm using JDOM2 to handle the XML that my application processes and would prefer to use the JDOM2 XSLT processing as well. From my XSLT, I'm hoping to call methods on java instances that have been created by my application prior to the call to the transformer.

Is this possible? If it is, can anyone point me in the right direction?

Thanks

DaveH
  • 7,187
  • 5
  • 32
  • 53
  • Are you talking about modifying the JDOM content from inside the XSLT transformation while the transformation is in progress? That sounds like it will lead to inconsistencies..... – rolfl Oct 01 '13 at 19:35
  • I need to populate an id field in the output document that is not present on the input. I have to set it in two places in the output document. I intended creating an object in java prior to the transformation to hold the value, and then using that value in the XSLT to populate the relevant fields in the output document. – DaveH Oct 01 '13 at 20:49
  • First thing we need to know is which XSLT processor you are using. (You said XSLT 2.0 but not which processor). Then google for "extension functions" against that processor. If you still have problems, let us know what they are. – Michael Kay Oct 01 '13 at 22:40
  • Looks like JDOM is using com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl - which I guess is the default implementation for the JVM? Would you suggest that it would be a better choice to specify a Transformaer to use explcitly, rather than relying on the JVM to serve one up to me? ( I'm writing a product that I hope will be hosted in any app server, on sites where I don't control the environment ) – DaveH Oct 02 '13 at 05:24
  • @MichaelKay - as a follow up, the document I read about using Java with xalan indicates that it can create an object instance within the style sheet and call methods on it. Is it also possible for it to be aware of objects that were created _before_ the transformer was called but are logically ( to me anyway ) still in scope, and call non-static methods on them? – DaveH Oct 02 '13 at 05:35
  • @DaveHowes (a) if you want XSLT 2.0 you'll need to ensure that Saxon is loaded. (b) For Saxon yes; probably also for Xalan, but I don't know Xalan in any detail. – Michael Kay Oct 02 '13 at 09:45

1 Answers1

0

You could solve your problem by passing the ID value as stylesheet parameter and write it to the output where appropriate? This would work for any XSLT Processor. This is a different approach but less complicated.