如何在 Marklogic 或 Couchbase 中进行 xslt 类型转换?

How to do xslt type transformations in Marklogic or Couchbase?

我正在研究用于数据连接和转换为其他数据结构的 noSQL 解决方案 - 特别是在 marklogic 和 couchbase。

我的问题:如何在基于 json 的数据库中进行类似 xslt 的转换?

我对 CouchBase 不够熟悉,无法评论它的功能。

MarkLogic 允许通过 REST PATCH requests. I wouldn't call it "like xslt" but it is definitely a way to update specific portions of JSON documents. Additionally, MarkLogic allows for server-side transformations written in Javascript 使用 XPath 或 JSONPath 进行简单转换(如果这更符合您的风格)。 MarkLogic 的 REST API、Java API 和 Node.JS API.

的用户可以使用转换和补丁

此外,MarkLogic 支持可以执行 RDF 转换的 SPARQL,如果这是选择的数据格式,并且可以序列化为 XML 或 JSON 格式。与 Couchbase 不同,RDF 三元组既可以在文档中表示,通常作为文档元数据,也可以作为三元组存储。文档既可以表示有关文档的元数据,也可以提供与基于外部 RDF 的类型化关系,包括链接的开放数据。

使用 MarkLogic JSON 模块将 JSON 转换为 XML 并使用 XSLT 语言:

xquery version "1.0-ml";
import module namespace json = "http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy";
declare variable $j := '{"content": {"name": "Joe Parent","children": [{"name": "Bob Child"}, {"name": "Sue Child"}, {"name": "Guy Child"}]}}';
let $doc := json:transform-from-json($j),
$params := map:map(),
$_put := map:put($params,"childName","Bob Child")
return xdmp:xslt-invoke("/templates.xsl",$doc,$params)

其中“/templates.xsl”被插入 模块 数据库:

xquery version "1.0-ml";
let $xslt:= <xsl:stylesheet version="2.0" exclude-result-prefixes="json" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:json="http://marklogic.com/xdmp/json/basic">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="childName"/>
<xsl:template match="json:content">
&quot;ParentName&quot;:<xsl:if test='$childName = json:children/json:json/json:name/text()'>&quot;<xsl:value-of select="json:name/text()"/>&quot;</xsl:if>
</xsl:template>
</xsl:stylesheet>
return xdmp:document-insert("/templates.xsl",$xslt)