xslt-1.0ibm-datapower

Read JSON Key Value and store it XSLT Variable


Please help me for XSLT code which will work in DataPower for following input

Input: {
   "Timestamp": "2018-12-19T10:52:21.0870605-05:00",
   "ResponseType": "Success",
    "Name":    [
            {
         "Code": "1001",
         "Description": "ABC",
         "Number": "123"         
      },
            {
         "Code": "1002",
         "Description": "XYZ",
         "Number": "123"   
      },
            {
         "Code": "1003",
         "Description": "PQA",
         "Number": "123"   
      },
            {
         "Code": "1004",
         "Description": "MNO",
         "Number": "123"   
      }
   ]
}

Output:

XSLT Variable

xsl:variable_code = 1001,1002,1003,1004

xsl:variable_Name : ABC,XYZ,PQA,MNO

Solution

  • XSLT will not work with this format natively (XSLT input is always XML, but output can be whatever).

    There are ways to get around this.

    1 - Use Gatewayscript transformation instead. You can find example on your own Datapower "sample" folders". The files are ending with ".js"

    2 - You can still do it in XSLT, but need to auto-convert the JSON to XML using the input settings and a special, hidden, magic variable. How-to:

    1. In your object (XML Firewall, or Multi-Protocol Gwy), Specify the input as "JSON"
    2. At the step in the rule where you want to use XSLT to interpret this input, do not use the vairable "PIPE" or "INPUT" as input, but "__JSONASJSONX". MORE INFO HERE.
    3. This will allow you to navigate the JSON file after conversion to XML.

    Here is an example of the conversion.

    The rest is just normal XSLT programming on the Datapower... you can create a JSON or XML output... your choice !