Announcement

Collapse
No announcement yet.

Transform XML using XSLT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transform XML using XSLT

    Hi,

    I am new with Mirth and I want to know how can I transform an XML in other XML using a XSLT.

    I have read that it is possible but I do not know how

    Thanks for answers.

  • #2
    Re:Transform XML using XSLT

    It's not easy. You could use the Java objetc to made the tranformation.

    It's not impossible, but you can do with JS more, and clearer.

    Comment


    • #3
      Re:Transform XML using XSLT

      Do you have any example how i could do it with javascript in mirth? I have searched the internet, but i could not find a suitable solution for that.

      i found this :
      Code:
      try {
      
          XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); 
             
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
          processor.process(new XSLTInputSource("games.xml"«»),
                            new XSLTInputSource("games.xsl"«»),
                          new XSLTResultTarget(bos));
      
          out.println(bos);
          
      } catch (Exception ex) {
          out.println(ex);
      }
      but that don't seems te be work

      Alessandro

      Post edited by: Alessandro, at: 01/16/2008 03:19

      Comment


      • #4
        Re:Transform XML using XSLT

        What's the error you're getting ?

        Comment


        • #5
          Re:Transform XML using XSLT

          Hi I changed the code to
          Code:
          XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); 
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          processor.process(new XSLTInputSource(msg), new XSLTInputSource("http://localhost/mirth.xsl"«»), new XSLTResultTarget(bos));
          channelMap.put(toXSL,bos)
          from the mirth valiation I get the error :

          Error on line 1: mising ; before statement (850f3251-df69-4a94-b8a0-eaf51bc97519#1)

          After that i change the code to :
          Code:
          processor = XSLTProcessorFactory.getProcessor(); 
          bos = new ByteArrayOutputStream();
          processor.process(new XSLTInputSource(msg), new XSLTInputSource("http://localhost/mirth.xsl"«»), new XSLTResultTarget(bos));
          channelMap.put(toXSL,bos)
          And i get the error

          ReferenceError: "XSLTProcessorFactory" is not defined.

          Post edited by: Alessandro, at: 01/16/2008 11:29

          Comment


          • #6
            Re:Transform XML using XSLT

            Hello,

            I have search the forum and the internet. I thing i need to import some xalan functions.

            import org.apache.xalan.xslt.XSLTProcessor

            http://xml.apache.org/xalan-j/samples.html

            But xalan is not installed. Can i dowloand xalan.jar and put it in the lib folder or do i need more?

            Comment


            • #7
              Re:Transform XML using XSLT

              Hi Alessandro,

              I emailed you this code snippet but I will post here in case someone else has the same problem. Here is the code I used to do the xslt transformation:

              importPackage(Packages.javax.xml.transform);
              importPackage(Packages.javax.xml.transform.stream) ;
              var tFactory = TransformerFactory.newInstance();
              var xslSource = new StreamSource("c:\\ORU-R01.xsl");
              var transformer = tFactory.newTransformer( xslSource );
              var bos = new java.io.ByteArrayOutputStream();
              var sbis = new java.io.StringBufferInputStream(msg);
              transformer.transform( new StreamSource(sbis),new StreamResult( bos ));
              msg = bos.toString();

              Hope that helps.
              Daniel Svanstedt
              Software Engineer
              Mirth Corporation

              Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
              Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

              Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

              Comment


              • #8
                Re:Transform XML using XSLT

                I am brand new to xslt and am wanting to do something like this but am finding resources to be inadequate. Can someone point me to a good tutorial on xslt that is focused on xml to xml transformation?

                Code:
                <?xml version="1.0" encoding="ISO-8859-1"?>
                <xsl:«»stylesheet version="1.0" xmlns:«»xsl="http://www.w3.org/1999/XSL/Transform">
                
                   <xsl:template match="/">
                
                      <xsl:for-each select="sample">
                         **change name of sample to aloquot**
                      </xsl:for-each>
                   </xsl:template>
                </xsl:«»stylesheet>
                the above example was borrowed from w3c schools

                Post edited by: fmason, at: 12/16/2008 14:42
                Fieran Mason-Blakley
                Standards Researcher
                Genologics Life Sciences

                Comment


                • #9
                  Re:Transform XML using XSLT

                  Take a look on Mirth 1.8. As far as i read the specs, it sould have build in XSLT transform support

                  http://www.mirthproject.org/communit...owse/MIRTH-842 - Add XSLT transformer support


                  Alessandro

                  Comment


                  • #10
                    Re:Transform XML using XSLT

                    Go Mirth 1.8.0!!

                    So this is essentially a best practices question but includes some nuts and bolts details

                    I make a REST call and get a response - I want to transform that response - it seems to me that the most appropriate place to do that is in at postprocessor step. In Mirth however, as of yet, there doesn't appear to be a transform step there. I can do it manually like I was about to in 1.7.1, but it seems like I should be able to take advantage of the built in xslt support - that would be a much cleaner way to do this.

                    I am also still struggling with the purpose and use of a number of the provided functions

                    Code:
                    responseMap.get('')
                    responseMap.put(connector, ResponseFactory.getSuccessResponse('message'))
                    These two for example seem like they would do a lot of what I am trying to accomplish. I don't know however, how to get a reference to my connector. There doesn't appear to be an id like there is with the channels, do I just need to dig through the source code and figure that out or is there more documentations somewhere?

                    I have found this, but am a little confused about precisely what it is suppose to do
                    http://www.mirthproject.org/index.ph...7&catid=2#5117

                    This for example

                    Code:
                    channelMap.put('SoapResponseXML', strXMLData);
                    looks really great, but I am not sure what the first parameter does.

                    http://www.mirthproject.org/index.ph...4&catid=2#7204

                    this one looks better - trying it now

                    Fieran

                    Post edited by: fmason, at: 12/17/2008 08:11

                    Post edited by: fmason, at: 12/17/2008 08:43

                    Post edited by: fmason, at: 12/17/2008 08:52

                    Post edited by: fmason, at: 12/17/2008 11:15
                    Fieran Mason-Blakley
                    Standards Researcher
                    Genologics Life Sciences

                    Comment


                    • #11
                      solution

                      So this accomplished what I wanted - I hope someone else can use it too.
                      Set up -
                      channel

                      inbound connector => httpListener
                      Respond from myHTTPSender
                      outbound connectors => httpSender, javascriptWriter

                      javascriptWritter code:

                      Code:
                      importPackage(Packages.javax.xml.transform);
                      importPackage(Packages.javax.xml.transform.stream);
                      
                      java.lang.System.out.println('Channel B - Transformer - response:\n' + responseMap.get('myHTTPSender').getMessage());
                      var tFactory = TransformerFactory.newInstance();
                      var xslSource = new StreamSource("path to xsl"«»);
                      var transformer = tFactory.newTransformer( xslSource );
                      var bos = new java.io.ByteArrayOutputStream();
                      var sbis = new java.io.StringBufferInputStream(responseMap.get('myHTTPSender').getMessage());
                      
                      transformer.transform( new StreamSource(sbis),new StreamResult( bos ));
                      
                      java.lang.System.out.println('Channel B - Transformer - transformed response:\n' + bos.toString());
                      
                      responseMap.get('myHTTPSender').setMessage( bos.toString() );
                      Fieran Mason-Blakley
                      Standards Researcher
                      Genologics Life Sciences

                      Comment


                      • #12
                        XSLT Problem

                        importPackage(Packages.javax.xml.transform);
                        importPackage(Packages.javax.xml.transform.stream) ;
                        var tFactory = TransformerFactory.newInstance();
                        var xslSource = new StreamSource("c:\\ORU-R01.xsl");
                        var transformer = tFactory.newTransformer( xslSource );
                        var bos = new java.io.ByteArrayOutputStream();
                        var sbis = new java.io.StringBufferInputStream(msg);
                        transformer.transform( new StreamSource(sbis),new StreamResult( bos ));
                        msg = bos.toString();


                        Hello

                        I need to get output file by adding xsl style on my given input xml file
                        What is the steps which I have to follow
                        I have input xml file and XLS file
                        When I manually combine these two with "<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>" these kind of include it will work
                        What Mirth can do for achieving this

                        Any help wuld be appreciated

                        Geo

                        Comment

                        Working...
                        X