The XSL Transform policy allows optional parameters to be set on the policy, per this topic:
http://apigee.com/docs/api-services/reference/xsl-transform-policy
and per the schema:
https://github.com/apigee/api-platform-samples/blob/master/schemas/policy/xsl.xsd
How are those parameters designed to be used? Can you provide an example or two?
Solved! Go to Solution.
Yes, here's an example. Suppose you have an XSL policy like this:
<XSL name="XSL-SubscriberNumbers-XformRequest"> <DisplayName>XSL - SubscriberNumbers - Request</DisplayName> <FaultRules/> <Properties/> <OutputVariable>request.content</OutputVariable> <Parameters ignoreUnresolvedVariables="false"> <Parameter name="uid" ref="authn.uid"/> <Parameter name="pwd" ref="authn.pwd"/> </Parameters> <ResourceURL>xsl://SubscriberNumbers-Request.xsl</ResourceURL> <Source>request</Source> </XSL>
We can see from reading it, it applies to the request message, and transforms the content in place. (returning the output to request.content).
This policy specifies two parameters, uid and pwd, which will be passed to the XSL. The values for those parameters are obtained from context variables, in this case, they are named authn.uid and authn.pwd , respectively. Values for those context variables need to have been set prior to the evaluation of this XSL policy.
Now let's look at the actual XSL sheet. You would refer to the passed parameters by name at the top of the XSL like this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cdm="http://example.com/cheesodatamodel.xsd"> <xsl:param name="uid" select="''"/> <xsl:param name="pwd" select="''"/> <xsl:output method="xml" omit-xml-declaration="yes" indent="no" media-type="string"/> <xsl:template ...> ... </xsl:stylesheet>
Then, you can retrieve those values in the XSL with a dollar-sign notation, like this:
<xsl:template match="/inquiry"> <soap:Envelope xmlns:mh="http://example.com/messageheader.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://example.com/soaprequest.xsd"> <soap:Header> <mh:MessageHeader> <cdm:userName><xsl:value-of select="$uid"/></cdm:userName> <cdm:userPassword><xsl:value-of select="$pwd"/></cdm:userPassword> </mh:MessageHeader> </soap:Header> <soap:Body> <q0:InquireRequest>...</q0:InquireRequest> </soap:Body> </soap:Envelope> </xsl:template>