Layer7 API Management

  • 1.  XSLT Transformation

    Posted Sep 28, 2017 03:37 AM

    Hi All,

     

            I am trying to use XSLT transformation assertion to make my scenario works but since i am not familiar with XSLT i am getting issues. Please find my scenario below and solve my problem.

     

    Scenario:  I have created the context variable and assigned some XML/JSON data. I have intentionally removed some data which i want pass thru XSLT.Could you please let me know how can i achieve this. Please find the data below.

     

    <school> 

         <class>

             <grade>first</grade>

             <age>3</age>

             <id>101</id>

             <contact>41864</contact>

        </class>

         <class>

             <grade>first</grade>

             <age>3</age>

             <id>101</id>

             <contact>null</contact>

        </class>

    </school>      

    --------

    --------

    Like this i have 20 rows data. Now if you observe I dont have data for contact so i want to pass some number anything whenever there is no data for particular this.

     

    Hope my scenario is clear.

     

    Thanks&Regards

    Rajasekhar 



  • 2.  Re: XSLT Transformation

    Broadcom Employee
    Posted Sep 28, 2017 04:00 AM

    Hello Rajasekhar ,

    If you just want replace  <contact>null</contact> to a fix number like  <contact>1234</contact>, it may be easier to use regular expression assertion.

     

    Regards,

    Mark



  • 3.  Re: XSLT Transformation

    Posted Sep 28, 2017 04:07 AM

    Hi Zhijun,

    '

         My intention is not this particular,if i am retrieving the data from DB that time whenever there is null i have to replace with some data.

         If possible could you please provide configuration of using Regex and also XSLT.

     

    Thanks&Regards

    Rajasekhar



  • 4.  Re: XSLT Transformation
    Best Answer

    Posted Sep 28, 2017 04:42 PM

    The 'Regular Expression Assertion' is certainly the easiest way to go. Here is a screenshot of what you need to configure:

     

    And this shows the 'Test' tab replacing 'null' with '12345'



  • 5.  Re: XSLT Transformation

    Broadcom Employee
    Posted Sep 28, 2017 08:34 PM

    Nice example Bill,

    Just in case there is null value for other xml element, using expression

    <contact>null</contact>

    could be more safe.

     



  • 6.  Re: XSLT Transformation

    Posted Oct 03, 2017 06:25 AM

    Hi Zhijun,

     

           Per suppose if i am getting the data from database, that time how to achieve this.

           Ofcourse i know the attribute name let say phonenumber. 

     

    Regards

    Rajasekhar



  • 7.  Re: XSLT Transformation

    Broadcom Employee
    Posted Oct 03, 2017 07:47 PM

    Hello Rajasekhar,

    It depends on the data format, can you give sample data before transform and after transform?

     

    Regards,

    Mark



  • 8.  Re: XSLT Transformation

    Broadcom Employee
    Posted Sep 28, 2017 09:09 PM

    Hello rajasekhar33 ,

    If you can achieve your goal with regex, don't think of xslt, regex is much faster than xslt.

     

    Regards,

    Mark



  • 9.  Re: XSLT Transformation

    Posted Oct 03, 2017 05:16 AM

    Thank you so much.

    This is exactly what i am looking for when i send the data thru XML.