Search code examples
jsonxsltgeojsonxslt-3.0jsondoc

XSLT embed json in a HTML


I have to take the input as JSON webpage and embed it in a HTML by using XSLT.

Input JSON is from this web page

I want to embed content of "coordinate" array in a script tag inside to a HTML page.

This my implementation:

      "type":"Feature",
      "geometry":{
        "type": "Polygon",
        "coordinates":<xsl:variable name="test" select="json-doc('https://deims.org/api/locations/4930521a-596f-4e6f-90b8-29696b8c1c98')"/>
<xsl:value-of select="$test?geometry?coordinates"/>
      }
    }

but return this only the numbers contents in the coordinates: 8.61638 45.962042 8.642529 45.962042 8.642529 45.949462 8.61638 45.949462 8.61638 45.962042, without brackets or commas.


Solution

  • Use serialize($test?geometry?coordinates, map { 'method' : 'json' }) (instead of $test?geometry?coordinates).