I am using XSLT 3.0 in Saxon-HE 9.8 and would like to work with JSON documents as linked data in JSON-LD. In JSON-LD, full HTTP URIs often appear as values.
When I use the XPath 3.1 fn:serialize
to round-trip the data back to JSON, the solidus characters in http://
are escaped. Is it possible to avoid this escaping when serializing back to JSON?
The fn:parse-json
function has an escape
parameter that can be set to true()
or false()
, but I don't see anything similar for fn:serialize
.
I can remove the escape characters with fn:replace
, but would like to know whether there is a built-in way to do it that I am missing.
An example stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:variable name="j" expand-text="no"> { "@context": "http://schema.org" } </xsl:variable>
<xsl:template name="init">
<xsl:sequence
select="
$j => parse-json(map {'escape': false(), 'liberal': true()})
=> serialize(map {'method': 'json'})
=> replace('\\/', '/')
"/>
</xsl:template>
</xsl:stylesheet>
Without fn:replace
, the result is {"@context":"http:\/\/schema.org"}
. With fn:replace
, the result is {"@context":"http://schema.org"}
.
let $j := ' { "@context": "http://schema.org" } ' return $j => parse-json(map {'escape': false(), 'liberal': true()}) => serialize(map {'method': 'json'})
with BaseX and with Altova and they too escape the/
as\/
so give"@context": "http:\/\/schema.org"
. – Haim