0
votes

I'm wondering if we lost custom java function support for XSLT-Stylesheets (available with Xalan in ESB 4.0.3) as Saxon is now the XSLT processor (HE edition) in WSO2 ESB 4.5 ?

Original XSLT, worked with ESB 4.0.3:

I copied the custom DateParser.jar in esb4.5.0/repository/components/dropins

<xsl:stylesheet extension-element-prefixes="transform" version="1.0"
   xmlns:transform="xalan://my.extension.DateParser"
     ...
   <xsl:value-of select="transform:sdf('dd.MM.yyyy HH:mm:ss',./timestamp)"/>

This showed up in the error log (shortened):

  ERROR XSLTMediator Unable to perform XSLT transformation using :
  Caused by: net.sf.saxon.trans.XPathException: Cannot find a matching  function named    {xalan://my.extension.DateParser}sdf()

Changed XSLT for Saxon, not working with ESB 4.5.0 ###

As Saxon handles custom java functions in a different way as Xalan does, I changed the XSLT-Stylesheet like this

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:transform="java:my.extension.DateParser" 
       ...
     <xsl:value-of select="transform:sdf('dd.MM.yyyy HH:mm:ss',./timestamp)"/>

Now this showed up in the error log (shortened):

 Caused by: net.sf.saxon.trans.XPathException: Cannot find a matching ... function named {java:my.extendsion.DateParser}sdf(). Note that direct calls to Java methods are not available under Saxon-HE

I'm wondering if there will be no support of "direct calls to Java methods" with standard WSO2 ESB distribution (containing Saxon-HE). As Saxon-Enterprise (paid version) will provide this support.

1
Did you face any issue to work with the older XSLT scripts in the new 4.5.0 version? If so, please provide the error stackRatha
Hi Ratha, I added some information to point to the problem.Jochen

1 Answers

0
votes

I could not find a way to get custom java functions invoked by XSLT-Stylesheets as the utilized XSLT-Processor SAXON-HE version prohibits this extension point.

Maybe this "workaround" or alternative approach might be helpful for others as it does the job, too:

Instead of invoking a custom java function within a XSLT-Stylesheet I transformed the message with a PojoCommand (this is just an example / debug snippet) within some sequence like this:

 <sequence>
    <log category="INFO" level="full" separator=","/>
    <pojoCommand name="foo.bar.DebugCommand">
     <property name="append" value="bar"/>
     <property action="ReadAndUpdateMessage" expression="//dummy3/text()" name="original"/>
    </pojoCommand>
    <log category="INFO" level="full" separator=","/>
    <drop/>
 </sequence>

Don't forget to the XPath-function /text() if your just want to transform the text-node and preserve the surrounding XML-Tags.

This is the DebugCommand implementation:

 import org.apache.synapse.Command;
  ...
 public class DebugCommand implements Command{

 private static Log log = LogFactory.getLog(DebugCommand.class);
 private String original = null;
 private String append = null;
 private String appendedOriginal;


 @Override
 public void execute() {
    log.info("Entering:"+toString());
    appendedOriginal = ""+original+":"+append;
    original = appendedOriginal;
    log.info("Exiting:"+toString());
 }


public String getOriginal() {
    return original;
}


public void setOriginal(String original) {
    this.original = original;
}


public String getAppend() {
    return append;
}


public void setAppend(String append) {
    this.append = append;
}


public String getAppendedOriginal() {
    return appendedOriginal;
}


public void setAppendedOriginal(String appendedOriginal) {
    this.appendedOriginal = appendedOriginal;
}


@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("DebugCommand [original=");
    builder.append(original);
    builder.append(", append=");
    builder.append(append);
    builder.append(", appendedOriginal=");
    builder.append(appendedOriginal);
    builder.append("]");
    return builder.toString();
}
  }