Advertisements

Thursday, February 6, 2014

Using java namespace with XSLT replace example

This is an example of how we can use basics Java functions (methods), sometimes it can be very useful. We will use the "Replace" function for the example.

This example only works when using an XSLT (Transform).

First take a look in the XSD which we are doing the example:




Then let's say that we want to replace any character of "&" (ampersand) that comes in the "Inputvariable" to the following character of "$" (dollar sign).

This is the XSLT that we need to implement the replace java function.



Now these are the steps for implementing the Java Replace Function.

1.- Add the following namespace
"xmlns:strClass="http://www.oracle.com/XSL/Transform/java/java.lang.String"




2.- Add the following Template at the bottom. (We have to use the HTML uni code name for the & its equivalence to unicode is \u0026)


  <xsl:template name="strReplace">
    <xsl:param name="param"/>
    <xsl:value-of select="strClass:replaceAll($param, '\u0026', '#')"/>
  </xsl:template>




3.- Add the "call-template" XSLT function and comment the actual mapping:


  <xsl:call-template name="strReplace">
    <xsl:with-param name="param"
          select="/client:process/client:input"/>
  </xsl:call-template>




Testing

After deploying the BPEL Composite in the EM using Hello$World.



We got:






No comments:

Post a Comment