Can we access the variables that we create as part of an XSLT in other policies?

Can we access the variables that we create as part of an XSLT in other policies? The requirement is to do the mapping in the XSLT and also to use the variables that were created as part of the XSLT in other policies (We are trying to avoid the Extract policy here and see if we can do the same as part of the xslt).

0 4 1,046
4 REPLIES 4

@bipin chandra debbad , You mean output variable (A variable that stores the output of the transformation.) ?

Hi Anil,

Hari has explained below exactly what i had tried to do in my Proxy and what i was trying to ask.Could you please let me know if you are aware of any way we can access these variables outside the XSL

Hi @bipin chandra debbad

I tried it out and it doesnt seem like it is possible.

Here is the XSL code that I wrote

<?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:variable name="MyJawDropped">HelpMeFindIt</xsl:variable>
        <xsl:text>Life - </xsl:text>
        <xsl:value-of select="$MyJawDropped"/>
    </xsl:template>
</xsl:stylesheet>

My XSLTransform policy's outputvariable is :

3828-xslout.png

I then setup an AssignMessage Policy as below :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignVariableFromXSL">
    <Properties/>
    <AssignVariable>
        <Name>var</Name>
        <Ref>MyJawDropped</Ref>
        <Value>default</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>response.content</Name>
        <Value>xxxxxx</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

This is what happens in the trace when this policy runs :

3829-assignmessagexsl.png

As you can see, the variable that I tried to create using the XSLT variable ended up with the default value. So basically, the variable created in the XSL does not survive outside the XSL.

Now if your purpose is to transform an XML and use the variables created therein inside the rest of flow, there might be a way. Apigee lets us use javascript to process XMLs in a limited fashion. You can check the below links :

Javascript Object Notation

Using asXML 1

Using asXML 2

Thanks Hari for trying it out. I had also done a similar thing in my proxy but was not able to access the variables.