Andre61
Andre61

Reputation: 15

Json string array without attributes transform XSLT

As the tittle says, I need some help to figure out how to transform JSON array without attributes to XSL.

(1)Input:

{
  "Body": {
    "name": "jhon",
    "ids": ["a", "b"]
  }
}

(2) The expected output should have this structure.

{
  "name": "jhon",
  "ids": ["a", "b"]
}

I have tried to transform it like this.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:output method="text"/>
    <xsl:variable name="path" select="*/Body"/>
    <xsl:template match="/">{
        "name" : "<xsl:value-of select="$path/name"/>",
        "ids" : "<xsl:value-of select="$path/ids"/>"
    }
</xsl:template>
</xsl:stylesheet>

But the Datapower is not able to transform the json array [ids], instead it returns this message "An error occurred when processing the message" and this output (3):

{
  "Body": {
    "Fault": {
      "faultcode": "",
      "faultactor": "",
      "detail": {
        "IntegrationError": ""
      }
    }
  }
}

If I remove "ids" field from request and transform XSL, it works ok. That's why I believe that I'm not transforming the array correctly.

Upvotes: 0

Views: 174

Answers (1)

Rajesh M
Rajesh M

Reputation: 1

you need to use for-each for id's check it online.

Upvotes: 0

Related Questions