我正在使用Saxon-HE 9.8中的XSLT 3.0,并希望将JSON文档作为链接数据与JSON-LD一起使用。在JSON-LD中,完整的HTTP URIs经常出现作为值。
当我使用XPath 3.1的
我可以使用
一个样式表的例子:
没有使用
当我使用XPath 3.1的
fn:serialize
将数据回转到JSON时,http://
中的斜杠字符被转义了。在序列化回JSON时,是否有可能避免这种转义?
fn:parse-json
函数具有一个可以设置为true()
或false()
的escape
参数,但我没有看到类似于fn:serialize
的内容。我可以使用
fn:replace
删除转义字符,但想知道是否有内置的方法可以做到这一点,而我却忽略了它。一个样式表的例子:
<?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>
没有使用
fn:replace
,结果为{"@context":"http:\/\/schema.org"}
。使用fn:replace
后,结果为{"@context":"http://schema.org"}
。
let $j := ' { "@context": "http://schema.org" } ' return $j => parse-json(map {'escape': false(), 'liberal': true()}) => serialize(map {'method': 'json'})
。它们也将/
转义为\/
,因此输出结果为"@context": "http:\/\/schema.org"
。 - Martin Honnen