No announcement yet.

Step by Step how to apply XSL to incoming HL7, etc

  • Filter
  • Time
  • Show
Clear All
new posts

  • Step by Step how to apply XSL to incoming HL7, etc

    I needed to apply XSL transformations to incoming HL7 data. NOTE: after using this, I realize I can't get Xalan to take non-XML input. This transformation does work with incoming XML however.

    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):

    // Create the transformer factory
    var tFactory = TransformerFactory.newInstance();
    // Load XSL file
    // XSL files are loaded based on the directory Mirth is running in'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;
    // Create an inputstream using the raw message
    var msg_sbis = new;
    // 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());
    Post edited by: fitek, at: 08/13/2008 14:43

  • #2
    Re:Step by Step how to apply XSL to incoming HL7,


    It would be very helpful if you could document it as example in the wiki