- I create an LLP listener
- I added a destination file writer
- I set the template to: ${message.transformedData}
- I clicked 'edit transformer'
- Click "Add New Step"
- Change the type to JavaScript
- Under the message templates tab, choose XML (or whichever format you wish to output) as the Outbound Message Template (DON'T FORGET THIS! I'd call this is a gotcha)Here is the code to load a stylesheet, apply it, and then save the results back to the message's transformedData member (mostly lifted from another post on this forum):
importPackage(Packages.javax.xml.transform);
importPackage(Packages.javax.xml.transform.stream);
// Create the transformer factory
var tFactory = TransformerFactory.newInstance();
// Load XSL file
// XSL files are loaded based on the directory Mirth is running in
logger.info('Message type is ' + messageObject.getType());
var xslSource = new StreamSource(messageObject.getType()+".xsl");
if (xslSource==null)
logger.error('error loading XSL');
// Create a new transformer using this transformation
var transformer = tFactory.newTransformer( xslSource );
var bos = new java.io.ByteArrayOutputStream();
// Create an inputstream using the raw message
var msg_sbis = new java.io.StringBufferInputStream(messageObject.getRawData()); // use msg to get internal Mirth XML representation
// Apply the XSL to the message
transformer.transform( new StreamSource(msg_sbis),new StreamResult( bos ));
// Set transformedData to be the new document
msg = new XML(bos.toString());
Note that you can come up with other types of combinations. For example, to forward several HL7 feeds to the same destination, create some channels with channel writer destinations and set message output type to 'HL7' in the message templates. Create a new channel with a channel reader source. Configure your destination and set the transformer to output the correct type via the message templates tab.
No comments:
Post a Comment