API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  XSLT replace value in xml payload with catalog variable

    Posted Thu November 23, 2023 01:44 PM
    Edited by Kenny Kew Thu November 23, 2023 01:50 PM

    Hi,

    I am trying to use the XSLT node in the policy to inject a block of XML to the request XML payload. However, there is a requirement to use a variable to for the value as the value can change from environment to environment.

    I tried the following XSLT I found to try to get the value from catalog variables, but the xsl:variable block select attribute doesn't work, so I am not sure I'll need to use some specific function or it is just some syntax error. 

    Thanks in advance.

    XSLT:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:com="http://pb.com/EngageOne/ws/common" xmlns:dp="http://www.datapower.com/extensions" xmlns:func="http://exslt.org/functions" xmlns:apim="http://www.ibm.com/xmlns/datapower/2017/11/apigateway" extension-element-prefixes="dp func apim">
        <!-- Contains the APIM functions -->
        <xsl:import href="local:///isp/policy/apim.custom.xsl"/>
        <xsl:output method="xml" indent="yes"/>
        <!-- identity transform -->
        <xsl:template match="*|@*|text()">
            <xsl:copy>
                <xsl:apply-templates select="*|@*|text()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='SearchDeliveryOptions']">
            <xsl:variable name="apic-id" select="apim:getContext('catalog.apic-id')"/>
            <xsl:copy>
                <com:authContext>
                    <com:UsernameToken>
                        <com:domain>
                            <com:ident>
                                <com:name>some value</com:name>
                            </com:ident>
                        </com:domain>
                        <com:userId>
                            <xsl:value-of select="$apic-id"/>
                        </com:userId>
                        <com:password>some value</com:password>
                        <com:transientSession>false</com:transientSession>
                    </com:UsernameToken>
                </com:authContext>
                <xsl:apply-templates select="*|@*|text()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>


    XML request:
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:del="http://pb.com/EngageOne/ws/deliveryManagement" xmlns:com="http://pb.com/EngageOne/ws/common">
        <soapenv:Header/>
        <soapenv:Body>
            <del:SearchDeliveryOptions>
                <!-- block to be injected -->
                <com:community>some value</com:community>
                <com:filter>some value</com:filter>
                <templates>
                    <template>
                        <ident>
                            <com:name>some value</com:name>
                        </ident>
                    </template>
                </templates>
            </del:SearchDeliveryOptions>
        </soapenv:Body>
    </soapenv:Envelope>




    ------------------------------
    Kenny Kew
    ------------------------------



  • 2.  RE: XSLT replace value in xml payload with catalog variable

    Posted Mon November 27, 2023 04:11 PM
    Edited by Steve Linn Mon November 27, 2023 04:15 PM

    Hi Kenny,
    A couple questions, first since you're using <xsl:import href="local:///isp/policy/apim.custom.xsl"/>, can I assume that you're using the v5 compatible gateway?  If not and using the native/API Gateway and still wish to use the apim namespaced extension function, you'll need to import store:///dp/apim.custom.xsl.  Also, can I assume that the variable you're trying to get with apim:getContext('catalog.apic-id'), ie catalog.apic-id, is a variable that was set in a prior policy in the assembly? Or perhaps this is an API property that has a catalog specific value? Or is this truly a catalog property?  If an API property with a catalog specific value it should be setup properly on publish to your specific catalog and you'd just need to get  either apic-id or api.properties.apic-id.  If this is a catalog specific property, then that is only available during publish and not at runtime, but what you can do is use a set variable policy that sets your own apic-id variable to a value of $(apic-id) and the API Manager will do the substitution at publish time in the set variable policy.

    Best Regards,
    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------