1

I am working on creating REST API's in IBM API connect. our requirement is to get the backend URL's from a property file which is present on the datapower gateway server and then invoke the back-end service in the API's.

In API assembly I have written the XSLT code to open the file and read the data from the file, but the xslt is returning an empty response.

XSLT Code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:dp="http://www.datapower.com/extensions" 
     xmlns:func="http://exslt.org/functions" 
     xmlns:apim="http://www.ibm.com/apimanagement"
     extension-element-prefixes="dp func apim"
     exclude-result-prefixes="dp func apim">

     <!-- Cotains the APIM functions -->
      <xsl:import href="local:///isp/policy/apim.custom.xsl"/>

                        <xsl:template match="/">
                        <xsl:variable name="FileContent">
                        <dp:url-open target="'https://localhost:9090/dp'" response="xml" data-type="filename">local:///policy/propertyfiles/URLs.xml
                        </dp:url-open>
                        </xsl:variable>
                        <xsl:variable name="policy-props" select="apim:policyProperties()"/>
                         <xsl:variable name="catalog" select="apim:getContext('env.path')"/>
                              <outputXml>
                              <data><xsl:copy-of select="$FileContent" /></data>
                              <catalog><xsl:value-of select="$catalog" /></catalog>
                              <xsl:for-each select="$FileContent/catalogs/catalog">
                                <xsl:variable name="ReferencedID" select="@name"/>
                                <xsl:choose>
                                  <xsl:when test="$ReferencedID = $catalog">
                                  <backend_url><xsl:value-of select="$FileContent/response/catalogs/catalog/backend_url" /></backend_url>
                                  </xsl:when>
                                </xsl:choose>
                              </xsl:for-each>
                            </outputXml>
                        </xsl:template>
                      </xsl:stylesheet>

I am expecting to see the data from the file in the xslt response . But I see the below response which is missing the data from the file.

Body:

    <?xml version="1.0" encoding="UTF-8"?>
    <outputXml>
     <data/>
     <catalog>sb</catalog>
  </outputXml>
Robur_131
  • 374
  • 5
  • 15
Sam
  • 21
  • 4

2 Answers2

0

Either use dp:url-open or possibly the document() function.

Another option is to add a GWS action to read the file and set it in a context variable.

Anders
  • 3,198
  • 1
  • 20
  • 43
  • I tried using dp:url-open ,but I am not sure if it is reading the file as I see an empty response. can you please provide more information on how to add a GWS action. I am new to XSLT and gatewayscript. – Sam Aug 30 '19 at 13:24
0

Use below XSLT code it will capture Reques-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions"
    xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"
    xmlns:func="http://exslt.org/functions"
    xmlns:apim="http://www.ibm.com/apimanagement" extension-element-prefixes="dp func apim" exclude-result-prefixes="xsl dp func apim">
    
    <!-- Contains the APIM functions -->
    <xsl:import href="local:///isp/policy/apim.custom.xsl" />
    
    <xsl:template match="/">
        <xsl:variable name="input" select="apim:payloadRead()" />
        <xsl:message>
            The input payload is
            <xsl:copy-of select="$input" />
        </xsl:message>
         </xsl:template>
    
</xsl:stylesheet>