Project

Profile

Help

Support #1950

closed

XSLT + java (extension functions, transition from MapForce)

Added by cos jacks over 10 years ago. Updated about 10 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
Saxon extensions
Sprint/Milestone:
-
Start date:
2013-12-07
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

I'm using mapForce to build an xslt2 file to map xml to xml. Then I'm using saxon HE to do the transformation via java at run time - This all works fine.

I would like to enhance my mapping capability by having the ability for the transformation java to call out to a custom java function to execute some difficult logic. But I also want to be able to use mapForce to build the xslt file and have my 'function' in its library so I can design with it. I think this is all possible but I'm getting confused as to how to put it together - Has any body done this, how was it done. Does an example exist.

If only portions of my requirements are possible - which bits & are there pointers as to how i might do it


Files

image001.jpg (371 Bytes) image001.jpg cos jacks, 2013-12-09 22:52
Actions #1

Updated by Michael Kay over 10 years ago

I'm afraid I don't know enough about MapForce to help with this one. I do know that Altova's and Saxon's conventions for calling extension functions are quite different, but there might be some common subset you can use.

Actions #2

Updated by cos jacks over 10 years ago

Thanks for response, its much appreciated.

Altova has a technique whereby within the xslt file you can add a namespace that binds to a java package & class type. Then within in the templates you can reference class/instance methods e.g.

         xmlns:car="java:com.altova.extfunc.Car?path=file:///C:/JavaProject/" >... <xsl:value-of select="car:getCarColor($myCar)"/>. 

Basically bring java into the xslt file.

Does saxon have a similar concept? I did browse the extensibility docs, but failed to spot anything that seems to be talking about this sort of technique?

From: Saxonica Developer Community [Masked] []

Sent: 08 December 2013 18:27

To:

Subject: [Saxon - Support #1950] xslt + java

Preview: --- In your reply, please do not write below this line --- Is

Safely received through a Masked Email. IF THIS IS SPAM, CLICK HERE TO BLOCK THIS MASKED EMAIL. https://emails.abine.com/disableDisposable?fwd=FWD_5Wpzz9k9@opayq.com

Actions #3

Updated by Michael Kay over 10 years ago

Saxon has "reflexive extension functions" which are quite similar (all the Java products have similar mechanisms, but the rules differ in detail). The Saxon mechanism is documented here: http://www.saxonica.com/documentation/index.html#!extensibility/functions

For calling static methods, which is the simplest case, you use a namespace like java:java.util.Date to identify the Java class, and the local name to identify the method within the class, and there is a defined set of mappings from XPath types to Java types for converting the parameters and the result. It's likely that in simple cases (strings, integers etc) these will be the same as the mappings used by Altova. If necessary you can use the "use-when" attribute so your stylesheet has different code for the Saxon and Altova cases.

Your example has a "path" parameter as part of the namespace; that isn't something Saxon supports. In Saxon, the class is always loaded from the classpath.

Actions #4

Updated by Michael Kay over 10 years ago

  • Subject changed from xslt + java to XSLT + java (extension functions, transition from MapForce)
  • Category set to Saxon extensions
  • Status changed from New to Resolved

Closing this: hopefully your questions have now been answered.

Actions #5

Updated by O'Neil Delpratt about 10 years ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF