7 Replies Latest reply on Oct 31, 2019 8:28 AM by saurabh shekhar

    Replacing the value inside xml tag in Adapter Response using XSLT Transformation

    saurabh shekhar
      Share This:

      Hello Team,

       

      Greetings of the Day!!

       

      I am working on one of the Automation use case and have got stuck at a point which involves XSLT transformation. In the below adapter response, there is one xml field named NACHA in which there are two values passed 2 and 5. I want to replace 2 with word  "ABC" and 5 with word "XYZ". Can you please let me know how i can make those changes using xslt transformation?

      A brief code would be helpful.

       

      <rest-adapter-response>

        <message-body>

          <asx:abap xmlns:asx="**********************" version="1.0">

            <asx:values>

              <PODATA>

      <item>

      <OBJKY>****</OBJKY>

      <ERDAT>****</ERDAT>

      <ERUHR>****</ERUHR>

      <USNAM>****</USNAM>

      <NACHA>2</NACHA>

      </item>

      <item>

      <OBJKY>****</OBJKY>

      <ERDAT>****</ERDAT>

      <ERUHR>****</ERUHR>

      <USNAM>****</USNAM>

      <NACHA>2</NACHA>

      </item>

      <item>

      <OBJKY>****</OBJKY>

      <ERDAT>****</ERDAT>

      <ERUHR>****</ERUHR>

      <USNAM>****</USNAM>

      <NACHA>5</NACHA>

      </item>

      <item>

      <OBJKY>****</OBJKY>

      <ERDAT>****</ERDAT>

      <ERUHR>****</ERUHR>

      <USNAM>****</USNAM>

      <NACHA>5</NACHA>

      </item>

              </PODATA>

            </asx:values>

          </asx:abap>

        </message-body>

        </rest-adapter-response>

       

      Thanks & Regards,

      Saurabh

        • 1. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
          Matthew Highcove

          This is a very straightforward transform that uses When and Otherwise to look for the values "2" and "5" and replaces them with "ABC" and "XYZ" respectively. There are likely more elegant solutions. You may also want to look into the XSLT 2.0 system adapter, which gives you access to the function fn:replace.

           

          <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asx="******" version="1.0">

            <xsl:output indent="no" />

            <xsl:template match="*">

              <PODATA>

                <xsl:for-each select="//PODATA/*">

                  <item>

                    <xsl:for-each select="./*">

                      <xsl:choose>

                        <xsl:when test=". = &quot;2&quot;">

                          <xsl:copy>

                            <xsl:text disable-output-escaping="no">ABC</xsl:text>

                          </xsl:copy>

                        </xsl:when>

                        <xsl:otherwise>

                          <xsl:choose>

                            <xsl:when test=". = &quot;5&quot;">

                              <xsl:copy>

                                <xsl:text disable-output-escaping="no">XYZ</xsl:text>

                              </xsl:copy>

                            </xsl:when>

                            <xsl:otherwise>

                              <xsl:copy-of select="." />

                            </xsl:otherwise>

                          </xsl:choose>

                        </xsl:otherwise>

                      </xsl:choose>

                    </xsl:for-each>

                  </item>

                </xsl:for-each>

              </PODATA>

            </xsl:template>

          </xsl:stylesheet>

          1 of 1 people found this helpful
          • 2. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
            saurabh shekhar

            Hello Matthew,

             

            Thanks for the response.

             

            I am somewhat confused regarding where to place the above code you have provided.

            Please find below the code which i have and let me know where should i place your code in that:

             

            <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

              <xsl:template match="/">

                <PODATA>

                  <html>

                    <body>

            <xsl:text disable-output-escaping="no">Hello User ,</xsl:text>

            <br />

            <br />

            <xsl:text disable-output-escaping="no">Below are the list of failed POs:</xsl:text>

            <br />

            <br />

            <b>

            <table border="1">

            <tr>

            <th>

            <xsl:text disable-output-escaping="no">PO Nmber failed in SOST</xsl:text>

            </th>

            <th>

            <xsl:text disable-output-escaping="no">Send method</xsl:text>

            </th>

            <th>

            <xsl:text disable-output-escaping="no">Date of Creation</xsl:text>

            </th>

            <th>

            <xsl:text disable-output-escaping="no">User who Created</xsl:text>

            </th>

            <th>

            <xsl:text disable-output-escaping="no">Time of creation/ Message Transmition</xsl:text>

            </th>

            </tr>

            <xsl:for-each select="//item">

            <tr>

            <td>

            <xsl:text disable-output-escaping="yes"> </xsl:text>

            <xsl:value-of select="OBJKY" disable-output-escaping="no" />

            </td>

            <td>

            <xsl:text disable-output-escaping="yes"> </xsl:text>

            <xsl:value-of select="NACHA" disable-output-escaping="no" />

            </td>

             

                              <td>

            <xsl:text disable-output-escaping="yes"> </xsl:text>

            <xsl:value-of select="ERDAT" disable-output-escaping="no" />

            </td>

            <td>

            <xsl:text disable-output-escaping="yes"> </xsl:text>

            <xsl:value-of select="USNAM" disable-output-escaping="no" />

            </td>

            <td>

            <xsl:text disable-output-escaping="yes"> </xsl:text>

            <xsl:value-of select="ERUHR" disable-output-escaping="no" />

            </td>

            </tr>

            </xsl:for-each>

            </table>

            </b>

                    </body>

             

             

             

             

             

            Result:

             

             

            Hello User ,

            Below is the table:

            PO Nmber failed in SOST

            Send method

            Date of Creation

            User who Created

            Time of creation/ Message Transmition

            ***********

            2

            2019-10-15

            ***********

            07:28:31

            ***********

            2

            2019-10-15

            ***********

            07:14:58

            ***********

            5

            2019-10-15

            ***********

            06:08:20

            ***********

            5

            2019-10-15

            ***********

            05:58:54

             

            Thanks & Regards,

            Saurabh

            • 3. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
              Aryan Anantwar

              Hi Saurabh,

               

              Was just looking at your posts recently and most of them are some basic dev activities.

              I suggest you to refer some BMC Docs and video's - TrueSight Orchestration (formerly BMC Atrium Orchestrator)https://www.youtube.com/watch?v=xzFzfaUYXD4&list=PLr4ck07lc-F90c2U2Qxd2RYbeYiEKylkr

              Along with this I'd suggest for BMC Trainings for Truesight orchestration. TrueSight Orchestration

               

              Regards,

              Aryan Anantwar

              1 of 1 people found this helpful
              • 4. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
                Matthew Highcove

                I gave you a full transform. I didn't know you already had a transform you were using to process the input because you didn't mention it. Now that I know what you are doing, I can modify what you have instead of creating something new:

                 

                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

                  <xsl:template match="/">

                    <PODATA>

                      <html>

                        <body>

                          <xsl:text disable-output-escaping="no">Hello User ,</xsl:text>

                          <br />

                          <br />

                          <xsl:text disable-output-escaping="no">Below are the list of failed POs:</xsl:text>

                          <br />

                          <br />

                          <b>

                            <table border="1">

                              <tr>

                                <th>

                                  <xsl:text disable-output-escaping="no">PO Nmber failed in SOST</xsl:text>

                                </th>

                                <th>

                                  <xsl:text disable-output-escaping="no">Send method</xsl:text>

                                </th>

                                <th>

                                  <xsl:text disable-output-escaping="no">Date of Creation</xsl:text>

                                </th>

                                <th>

                                  <xsl:text disable-output-escaping="no">User who Created</xsl:text>

                                </th>

                                <th>

                                  <xsl:text disable-output-escaping="no">Time of creation/ Message Transmition</xsl:text>

                                </th>

                              </tr>

                              <xsl:for-each select="//item">

                                <tr>

                                  <td>

                                    <xsl:text disable-output-escaping="yes"> </xsl:text>

                                    <xsl:value-of select="OBJKY" disable-output-escaping="no" />

                                  </td>

                                  <td>

                                    <xsl:text disable-output-escaping="yes"> </xsl:text>

                                    <xsl:choose>

                                      <xsl:when test="NACHA = &quot;2&quot;">

                                        <xsl:text disable-output-escaping="no">ABC</xsl:text>

                                      </xsl:when>

                                      <xsl:otherwise>

                                        <xsl:choose>

                                          <xsl:when test="NACHA = &quot;5&quot;">

                                            <xsl:text disable-output-escaping="no">XYZ</xsl:text>

                                          </xsl:when>

                                          <xsl:otherwise>

                                            <xsl:value-of select="NACHA" disable-output-escaping="no" />

                                          </xsl:otherwise>

                                        </xsl:choose>

                                      </xsl:otherwise>

                                    </xsl:choose>

                                  </td>

                                  <td>

                                    <xsl:text disable-output-escaping="yes"> </xsl:text>

                                    <xsl:value-of select="ERDAT" disable-output-escaping="no" />

                                  </td>

                                  <td>

                                    <xsl:text disable-output-escaping="yes"> </xsl:text>

                                    <xsl:value-of select="USNAM" disable-output-escaping="no" />

                                  </td>

                                  <td>

                                    <xsl:text disable-output-escaping="yes"> </xsl:text>

                                    <xsl:value-of select="ERUHR" disable-output-escaping="no" />

                                  </td>

                                </tr>

                              </xsl:for-each>

                            </table>

                          </b>

                        </body>

                      </html>

                    </PODATA>

                  </xsl:template>

                </xsl:stylesheet>

                 

                I also recommend looking into some online tutorials for XSLT. XSLT Transforms are not a system unique to TSO, and there are many online resources to help you learn how to write your own transforms.

                1 of 1 people found this helpful
                • 5. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
                  saurabh shekhar

                  Hello Matthew,

                   

                  This seems to be working!!

                   

                  I have one more query apart from this.

                  If i want to send each row in a separate mail to different users how we can do that?

                  Is there anything we need to do in the xslt transformation itself or some other way i need to make this work?

                   

                  PO Nmber failed in SOST

                  Send method

                  Date of Creation

                  User who Created

                  Time of creation/ Message Transmition

                  ***********

                  2

                  2019-10-15

                  ***********

                  07:28:31

                  ***********

                  2

                  2019-10-15

                  ***********

                  07:14:58

                  ***********

                  5

                  2019-10-15

                  ***********

                  06:08:20

                  ***********

                  5

                  2019-10-15

                  ***********

                  05:58:54

                   

                  Thanks & Regards,

                  Saurabh

                  • 6. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
                    Matthew Highcove

                    There is no way to send multiple emails as part of a single XSLT transformation. XSLT transformations produce XML documents; they do not interact with external systems or adapters. Please consider the links Aryan Anantwar posted for basic information about TrueSight Orchestration and what its components do.

                     

                    To do this, use a For loop that runs once for each row (except the header). Inside that For loop, use a Mail adapter to send an email via either a Call Adapter activity or one of the out-of-the box workflows. You can add the information from the current row in the email.

                    1 of 1 people found this helpful
                    • 7. Re: Replacing the value inside xml tag in Adapter Response using XSLT Transformation
                      saurabh shekhar

                      Hello Aryan,

                       

                      Yeah i am bit new to this Xslt transformation. I am still going through various websites and understanding how this works.

                      Certainly these documents will help me in getting xslt things clear.

                       

                      Thanks & Regards,
                      Saurabh