1
votes

I'm trying to use the XSLT Mediator but when taking a value, i'd like to apply a custom groovy function to it. For example:

<script language="groovy">
  def myfunction(value) {
     return "A B C";
  }
</script>

<xsl:template match="/">
   <urn:item>
      <urn:productName>
         <xsl:value-of select="myfunction(PRODUCTNAME)"/>
      </urn:productName>
   </urn:item>
</xsl:template>

The error i'm getting is: net.sf.saxon.trans.XPathException: Cannot find a matching 1-argument function named myfunction()

As i read, Saxon HE (the default xslt processor in wso2esb) is not able to call extension functions but Saxon PE or EE does.

I follow steps detailed here (http://nandikajayawardana.blogspot.com.ar/2012/12/how-to-replace-saxonhe940wso2v1jar-in.html) but same error.

My question is: Is there another way to do what i need? How can i know that wso2 esb is loading properly Saxon EE?

Thank you very much for your help!

Regards, R.

=====================================================

Solved!

  • Follow @Carpentidge steps to install Saxon EE in WSO2ESB.

  • Following @MichaelKay link, i used Java to do what i need

First, download common-lang3.jar.zip and copy the .jar file into repository/components/lib. Then, modify the xslt as follows:

<xsl:template match="/">
   <xsl:variable name="pn" select="CSITPRODUCTNAME"/>
   <urn:item>
      <urn:productName>
         <xsl:value-of select="lang:unescapeHtml($pn)" xmlns:lang="java:org.apache.commons.lang.StringEscapeUtils"/>
      </urn:productName>
   </urn:item>
</xsl:template>

Thank you both for your help @Carpentidge and @MichaelKay

2

2 Answers

0
votes

Saxon doesn't support extension functions written in groovy, and it doesn't recognize the <script> element in a stylesheet file. Saxon's mechanisms for defining extension functions are described here:

http://www.saxonica.com/documentation/#!extensibility

0
votes

The manual for replaxing saxon you reference is not for the ESB :) To replace saxon for the esb, put the saxon9ee.jar in the ESB_HOME\lib\endorsed folder and remove the saxon_HE file. Put the license file in the ESB_HOME folder (you can request a temporary one from saxonica.com) and restart the ESB. I had some difficulties using 9.6.0 so I'd say use 9.5.1. http://www.saxonica.com/download/download_page.xml