How to use the XSL Transform policy in Apigee Edge?

Not applicable

I’m trying to use the Apigee Edge environment to do some XSL transforms. I have an XML file coming in as a request, and I’ve added an XSL Transform policy in the PostFlow of the Proxy Endpoint I built. Unfortunately, no matter what I write in the XSLT file, the XML is not transformed. I’ve read the help page on Apigee’s site regarding the policy, but there are no tips about how to use the develop and trace tools specifically, so I’m sure there must be something I’m missing.

Here is the the XML request:

<STOCKQUOTE ROWCOUNT="1">
<RESULT>
<ROW>
<ASK>54.280</ASK>
<BID>54.270</BID>
<CHANGE>-0.360</CHANGE>
<DIVIDEND>0.160</DIVIDEND>
<EPS>1.725</EPS>
<HIGH>54.390</HIGH>
<LASTPRICE>54.260</LASTPRICE>
<LOW>53.680</LOW>
<OPEN>53.870</OPEN>
<PCHANGE>-0.659</PCHANGE>
<PE>14.000</PE>
<PREVIOUSCLOSE>54.620</PREVIOUSCLOSE>
<YEARHIGH>54.750</YEARHIGH>
<YEARLOW>35.385</YEARLOW>
<YIELD>1.172</YIELD>
</ROW>
</RESULT>
<STATUS>No Error</STATUS>
<STATUSCODE>0</STATUSCODE>
</STOCKQUOTE>

Here is the XSL Transform (written in the Apigee client):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="ROW/*[not(name()='LASTPRICE')]">
        <xsl:copy-of select="."/>
    </xsl:template>

    <xsl:template match="LASTPRICE">
        <TRADE>
            <xsl:value-of select="."/>
        </TRADE>
    </xsl:template>
</xsl:stylesheet>

In Visual Studio, this transform simply changes the attribute <LASTPRICE></LASTPRICE> to <TRADE></TRADE>.

Here is the response from the trace tool (the LASTPRICE attribute has not been changed):

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE STOCKQUOTE PUBLIC '-//W3C//DTD StockQuote 1.5//EN' 'http://www.irxml.org/dtd/stockquote_1.5.dtd'><STOCKQUOTE ROWCOUNT='1'><RESULT><ROW><ASK>54.230</ASK><BID>54.220</BID><CHANGE>-0.394</CHANGE><DIVIDEND>0.160</DIVIDEND><EPS>1.725</EPS><HIGH>54.390</HIGH><LASTPRICE>54.226</LASTPRICE>.....
Solved Solved
1 5 2,498
1 ACCEPTED SOLUTION

Former Community Member
Not applicable

Hi @Therese Marchant, please try using this sample proxy (attached) that I have created. You can import it as an API Bundle

I sent the following xml request

<STOCKQUOTE ROWCOUNT="1">
<RESULT>
<ROW>
<ASK>54.280</ASK>
<BID>54.270</BID>
<CHANGE>-0.360</CHANGE>
<DIVIDEND>0.160</DIVIDEND>
<EPS>1.725</EPS>
<HIGH>54.390</HIGH>
<LASTPRICE>54.260</LASTPRICE>
<LOW>53.680</LOW>
<OPEN>53.870</OPEN>
<PCHANGE>-0.659</PCHANGE>
<PE>14.000</PE>
<PREVIOUSCLOSE>54.620</PREVIOUSCLOSE>
<YEARHIGH>54.750</YEARHIGH>
<YEARLOW>35.385</YEARLOW>
<YIELD>1.172</YIELD>
</ROW>
</RESULT>
<STATUS>No Error</STATUS>
<STATUSCODE>0</STATUSCODE>
</STOCKQUOTE>

and received the following xml response.

<?xml version="1.0" encoding="UTF-8"?>
<STOCKQUOTE ROWCOUNT="1">
    <RESULT>
        <ROW>
            <ASK>54.280</ASK>
            <BID>54.270</BID>
            <CHANGE>-0.360</CHANGE>
            <DIVIDEND>0.160</DIVIDEND>
            <EPS>1.725</EPS>
            <HIGH>54.390</HIGH>
            <TRADE>54.260</TRADE>
            <LOW>53.680</LOW>
            <OPEN>53.870</OPEN>
            <PCHANGE>-0.659</PCHANGE>
            <PE>14.000</PE>
            <PREVIOUSCLOSE>54.620</PREVIOUSCLOSE>
            <YEARHIGH>54.750</YEARHIGH>
            <YEARLOW>35.385</YEARLOW>
            <YIELD>1.172</YIELD>
        </ROW>
    </RESULT>
    <STATUS>No Error</STATUS>
    <STATUSCODE>0</STATUSCODE>
</STOCKQUOTE>

Let me know if this does what you want.

View solution in original post

5 REPLIES 5

Former Community Member
Not applicable

@Therese Marchant can you post a sample xml request file and your xslt file? Also curious to see what you see on the output of the trace tool.

Question has been edited!

I am pretty new to apigee environment and after reading this post still don't know how to upload an xml file as a request and get a transformed xml in response. I imported the API bundle that you provided and tried to import an xml using trace tool, however, I was not successful.

Thanks for your help.

Former Community Member
Not applicable

Hi @Therese Marchant, please try using this sample proxy (attached) that I have created. You can import it as an API Bundle

I sent the following xml request

<STOCKQUOTE ROWCOUNT="1">
<RESULT>
<ROW>
<ASK>54.280</ASK>
<BID>54.270</BID>
<CHANGE>-0.360</CHANGE>
<DIVIDEND>0.160</DIVIDEND>
<EPS>1.725</EPS>
<HIGH>54.390</HIGH>
<LASTPRICE>54.260</LASTPRICE>
<LOW>53.680</LOW>
<OPEN>53.870</OPEN>
<PCHANGE>-0.659</PCHANGE>
<PE>14.000</PE>
<PREVIOUSCLOSE>54.620</PREVIOUSCLOSE>
<YEARHIGH>54.750</YEARHIGH>
<YEARLOW>35.385</YEARLOW>
<YIELD>1.172</YIELD>
</ROW>
</RESULT>
<STATUS>No Error</STATUS>
<STATUSCODE>0</STATUSCODE>
</STOCKQUOTE>

and received the following xml response.

<?xml version="1.0" encoding="UTF-8"?>
<STOCKQUOTE ROWCOUNT="1">
    <RESULT>
        <ROW>
            <ASK>54.280</ASK>
            <BID>54.270</BID>
            <CHANGE>-0.360</CHANGE>
            <DIVIDEND>0.160</DIVIDEND>
            <EPS>1.725</EPS>
            <HIGH>54.390</HIGH>
            <TRADE>54.260</TRADE>
            <LOW>53.680</LOW>
            <OPEN>53.870</OPEN>
            <PCHANGE>-0.659</PCHANGE>
            <PE>14.000</PE>
            <PREVIOUSCLOSE>54.620</PREVIOUSCLOSE>
            <YEARHIGH>54.750</YEARHIGH>
            <YEARLOW>35.385</YEARLOW>
            <YIELD>1.172</YIELD>
        </ROW>
    </RESULT>
    <STATUS>No Error</STATUS>
    <STATUSCODE>0</STATUSCODE>
</STOCKQUOTE>

Let me know if this does what you want.

Hi @Therese Marchant,

Are you using our virtual cloud (on-premises) solution, or an enterprise organization, or a developer (free) organization?

Some things to keep in mind:

  1. By default, the XSL policy works on the default message for the particular flow you are in. For example, it will default to using the request message if you attach the XSL policy in the request flow. You can use the Source parameter to change that, but it must be of type message (not a string).
  2. By default, the XSL policy will modify in place, but you can specify a string variable that will get the changed payload, using the OutputVariable parameter. This is a string variable (not a message variable as in the Source parameter). If you want it to go to a message, you'd use message.content (request.content, etc.).
  3. The XSL policy won't run if the current content-type for the message (the header Content-Type) is not an XML type. So if you change the Content-Type to application/json, for example, before the XSL policy, it won't do anything.