I am not quite clear on the end goal you have. Specifically I cannot understand this part:
the input the codes at name field inside the pair tag should be replaced with respective json field and also for this respective pair the respective Int and double values also should be printed under the json field.
I tried reading it several times but I don’t get it. But I can provide some information about reading from a second XML document in the XSLT. And also a suggestion that maybe you don’t really want to do that.
OK, on item #1. Normally an XSLT has two inputs: the source XML document, and the XSL sheet. I think you are saying that you would like some additional information to be accessible by the XSL, and that information itself is formatted as XML. This is possible to do, but not with the builtin XSL policy included with Apigee Edge.
Some time ago I built a custom Java callout that performs XSL transforms, and adds a few capabilities that the builtin XSL policy lacks. One of those capabilities is the ability to instantiate a document object within the XSL, from a string. Find the custom callout here: https://github.com/DinoChiesa/ApigeeEdge-Java-Xslt
There is a readme there that describes how to use the data: URI scheme to instantiate a document within your XSL, from the string that contains the XML. You only need to assign your XML string value to a variable, possibly in the policy config, like this:
<JavaCallout name='JavaCallout-Xslt-1'>
<Properties>
<Property name='xslt'>{xslturl}</Property>
<Property name='engine'>saxon</Property>
<Property name='input'>response</Property>
<Property name='output'>response.content</Property>
<!-- parameter to pass to the XSLT -->
<Property name='param_map'><Data>
<code id="30031">
<Jsonfield>Clearing</Jsonfield>
</code>
<code id="30030">
<Jsonfield>memo</Jsonfield>
</code> </Data></Property>
</Properties>
<ClassName>com.google.apigee.edgecallouts.xslt.XsltCallout</ClassName>
<ResourceURL>java://edge-custom-xslt-1.0.9.jar</ResourceURL>
</JavaCallout>
…then in the XSL, you would do something like this:
<xsl:param name="map" select="''"/>
<xsl:variable name="mapxml" select="document(concat('data:text/xml,',$map))"/>
...
<xsl:for-each select="$mapxml/Data/code"> ...
You cannot use the data: URI scheme in the builtin XSL policy. You need the callout for that to work.
Now for item #2. While I am confident that this custom callout will work for your purposes, I think maybe it might be more than you need. If you can format your configuration in something that is not XML, then you can just parameterize the builtin XSL policy. This might be a good example:
<XSL name='XSL-1'>
<Source>message</Source>
<OutputVariable>transformedContent</OutputVariable>
<ResourceURL>xsl://1.xsl</ResourceURL>
<Parameters ignoreUnresolvedVariables='true'>
<Parameter name='map'>30031:Clearing|30030:memo|30027:notes</Parameter>
</Parameters>
</XSL>
You can see I’ve transformed the data that was in your original configuration XML above, into a delimited string. In the XSL itself, you can reference that parameter like this:
<xsl:param name="map" select="''"/>
You would then need to parse the map string… split it by pipes, then split those things by colons. In XSL 2.0, you can use the tokenize() function to do that. like this:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
encoding="utf-8"
indent="yes"
xslt:indent-amount="2" xmlns:xslt="http://xml.apache.org/xslt" />
<xsl:strip-space elements="*"/>
<xsl:param name="map" select="''"/>
<!-- eg, 30031:Clearing|30030:memo|30027:notes -->
<xsl:template match="/">
<mapitems>
<xsl:for-each select="tokenize($map,'\|')">
<xsl:call-template name="split_one">
<xsl:with-param name="item" select="." />
</xsl:call-template>
</xsl:for-each>
</mapitems>
</xsl:template>
<xsl:template name="split_one">
<!-- input is like 30030:memo -->
<xsl:param name="item" />
<code>
<xsl:attribute name='id'><xsl:value-of select="tokenize($item,':')[1]"/></xsl:attribute>
<JsonField><xsl:value-of select="tokenize($item,':')[2]"/></JsonField>
</code>
</xsl:template>
</xsl:stylesheet>
Obviously that’s not exactly what you want. It sounds like you want to use the 30030 / memo stuff as metadata that somehow drives the operation of the transform. As I said above I don’t really understand what you were intending, so I cannot give you a working example that solves your problem. The above XSL just shows you how to tokenize a string and might get you a little further down the path toward your goal.