Use
The XSLT specification proposes an enhancement mechanism that enables the system to call external routines from XSLT for transforming XML structures. Java is a programming language that is supported by some Java XSLT processors as an enhancement language.
Using the XSLT mapping with Java enhancement, you can implement mappings quicker and more flexibly.
The working draft of the specification for XSL Transformations (XSLT) version 2.0 (version from December 20, 2001), does not define the features of the enhancement mechanism of the XSL transformation. There are also no accompanying standards that standardize the enhancement mechanism with Java. For this reason, XSLT processors available on the open market vary considerably in this respect.
Below is a description of one of the ways that the SAP J2EE Engine supports the XML Toolkit 2.0.
Activities
To implement an XSLT mapping with Java enhancement, proceed as follows:
...
1. Implement a Java class that contains the static methods of transforming XML documents or structures. Within this Java class you can also write messages to a trace that is visible in the message monitoring using the MappingTrace object.
The PCK does not support the MappingTrace object.
2. Include the method calls in the XSLT mapping program (see below).
3. Import the XSLT mapping program and the Java class as an archive to the Integration Repository. You can also use two different archives. The archive with the Java class must be in the same or an underlying software component version of the XSLT mapping program (see also: XSLT and Java Mapping).
The following example illustrates the procedure using a simple XSLT mapping for a message.
Example
The following table shows the message instance that you want to transfer to the target message, using an XSLT mapping program with Java enhancement.
Source Instance | Target Instance |
|
|
You must link the
...
1. Declare the Java class with a namespace definition as an attribute of the
2. Use
○ The first parameter takes the value of the
○ The last parameter takes the value of the
○ The parameter name inputparam is defined and enables you to transfer the constants of the StreamTransformationConstants class to the Java program.
In a Java mapping you have to implement the setParameter() method to enable the Integration Server to set the constants at runtime. For XSLT mappings with a Java enhancement it is sufficient to transfer the constants using the inputparam parameter. The mapping runtime sets the parameter. (see also: Java Mapping).
3. The method is called with the element
SAP advises you to check the availability of methods before you call them. Test the XSL element
The XSLT program looks like this:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:javamap="java:com.company.group.MappingClass">
The concat() class method of the Java class com.company.group.MappingClass groups the values of the
package com.company.group;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformationConstants;
public class MappingClass {
private static AbstractTrace trace = null;
public static String concat(String first,
String last,
Map inputparam)
{
// write trace information
trace = (AbstractTrace)inputparam.get(
StreamTransformationConstants.MAPPING_TRACE );
trace.addInfo(“concat():
\nfirst-name = “ + first +
“\nlast-name = “ + last );
// return concatentation
return first + ' ' + last;
}
//...
}
No comments:
Post a Comment