I have a complex XML document that the informatica XML parser struggles with "normalizing", how can I run a XML transformation such as XSLT to simplfy it prior to sending it into the XML parser.
One way of doing this is to use the standard Java transform and use the standard javax.xml.transform
API to perform the transformation.
To do this add a Java Transform to your flow
In the Import Packages
pane, import the required java packages
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
In the Helper Code
pane we construct a transformer object. As I understand non static fields are created per instance, so there should be no concurrency issues. (comments?)
private final Transformer transformer = getNewTransformer();
public Transformer getNewTransformer()
{
// /opt/informatica/infadev/DataTransformation
final String IFCMPath = System.getenv("IFCONTENTMASTER_HOME");
final String xslt = IFCMPath + "/ServiceDB/xst/mytransform.xslt";
logInfo("Using XSLT File" + xslt);
try{
return TransformerFactory.newInstance().newTransformer(new StreamSource(xslt));
} catch(TransformerConfigurationException ex) {
logError("Could not create TransformerFactory with xslt " + xslt );
}
return null;
}
Finally we execute the transform on the incoming xml document by executing the transform method on the transformer object.
if( transformer == null ) {
failSession("Transformer was null");
}
//final long startTime = System.nanoTime();
//final long endTime;
try {
//logInfo("Recieved xml with size " + xmlin.length() );
// logInfo("Recieved xml " + xmlin );
final StringReader reader = new StringReader(xmlin);
final StringWriter writer = new StringWriter();
transformer.transform(new StreamSource(reader),new StreamResult(writer));
xmlout = writer.toString();
// logInfo("xmlout " + xmlout );
} catch (Exception e) {
incrementErrorCount(1);
logError(e.getMessage());
logError(xmlin);
}
//finally {
// endTime = System.nanoTime();
//}
//final long duration = endTime - startTime;
//logInfo("Duration " + duration / 1000000000.0 );