Trying out XSL. OutputVariable not being populated after execution of the policy

I have only two policies in the preflow. One XSL and another javascript to read the the output variable of the XSL policy

XSL

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="XSL_Transform_SOAP_Request">
    <DisplayName>XSL_Transform_SOAP_Request</DisplayName>
    <ResourceURL>xsl://XSL-Transform-soap-request.xsl</ResourceURL>
    <OutputVariable>testXslVar</OutputVariable>
</XSL>

XSLT

<?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="/">
        <root/>
    </xsl:template>
</xsl:stylesheet>

In trace I can see the variable testXslVar with no value after execution of the XSL policy. Also I added a javascript policy to print the variable using the code print(context.getVariable("testXslVar")); and it printed null value.

Am i messing something?

0 8 2,226
8 REPLIES 8

Hi

You can do the steps you mentioned by following these steps:

1) Extract the values from the request (from qp and headers) using Extract Variables policy

2) Using Assign Message policy, create the SOAP request that needs to be sent to the Target system

For example

<Set>
    <Verb>POST</Verb>
    <Payload contentType="text/xml"><![CDATA[
        <?xml version="1.0" encoding="UTF-8"?>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.example.com/secure">
           <soapenv:Header />
           <soapenv:Body>
              <v1:PaymentRequest>
                 <v1:applicationName>jPayment</v1:applicationName>
                 <v1:user>jPayment</v1:user>
                 <v1:creditCardNumber>{saveRequestPrefix.cardNumber}</v1:creditCardNumber>
              </v1:PaymentRequest>
           </soapenv:Body>
        </soapenv:Envelope>
        ]]></Payload>
</Set>

In the above sample saveRequestPrefix.cardNumber is one of the variables extracted in step 1. You can include the variables and build the SOAP Request

3) Once you get the response, you can use the XSLT Policy to get a new XML (in this case, the Source element in the policy needs to be set as response - see policy docs)

4) Use XMLToJSON policy to convert the response into JSON format

Hope this helps

Thank you @Sai Saran Vaidyanathan for the reply. I understand that it can be done in your way. Is my way is not supported in apigee? Cause in my way i will have only one policy XSL transform which has three params to get the attribute value from header and qp. It is very simplified way i think. I have another example where extract variable, assign message, json-to-xml and finally XSL transform policy used in preflow to generate SOAP message, however in my case using only XSL transform not working.

This is kind of strange behavior!

Thanks,

Krishanu

Hi - I dont think you can. According to what you said - you dont need to use XSL policy. You can directly build the SOAP Request using Assign Message policy. You are not transforming one form to another. But on the response - you can use XSL policy.

Hi @Sai Saran Vaidyanathan I got the point that i don't need XSL policy as i am not converting one xml into another. But xsl policy is working fine when my resource type is POST and content-type is application/xml. The policy should not work regardless method type and content-type. Is this an apigee issue?

Thanks,

Krish

@docs

Seems like XSL policy works only for POST calls. Can this be documented explicitly if thats the case ?

Hey @Sai Saran Vaidyanathan - Before I update the docs, can you please file an Eng ticket to see if this is a product bug? Thanks.

Will do. Thanks @Floyd Jones

Ok. I got the issue. I was using application/json as content type. I am wondering how why apigee has restriction that it will work only for "application/xml". Also I have noticed that It will only work if the resource type is POST.

Let's consider a scenario I am working on now. I have to design a rest GET api which takes values from query params and header params and form a SOAP request.

Can I not use xsl transformation for this? Currently XSL is properly accepting these inputs from query/header and forming SOAP message. But as soon as I change the method GET and send a request from postman I am getting

 {
  "fault": {
    "faultstring": "Evaluation of XSL XSL-Transform-soap-request.xsl failed with reason: \"Premature end of document while parsing at line 1(possibly  around char 0)\"",
    "detail": {
      "errorcode": "steps.xsl.XSLEvaluationFailed"
    }
  }
}

If i change the content-type as application/json nothing happen. the policy is simply ignored.

I want to design the proxy as bellow.

1. Use a XSL transformation policy to form the SOAP message for the target end point.

2. Once SOAP response message is received will transform the message in a nice XML using XSL transformation policy.

3. Apply XM-to-JSON policy to convert the xml to json for final output to the consumer.

Is the any issue in the above design? Please help.