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

问题描述 投票:1回答:3

我正在寻找一种用于数据连接和转换到其他数据结构的noSQL解决方案 - 特别是在marklogic和couchbase。

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

couchbase marklogic nosql
3个回答
5
投票

我对CouchBase不太熟悉,不能评论它的功能。

MarkLogic允许通过REST PATCH requests使用XPath或JSONPath进行简单转换。我不会把它称为“像xslt”,但它绝对是一种更新JSON文档的特定部分的方法。此外,MarkLogic允许使用server-side transformations written in Javascript,如果这更符合您的风格。 MarkLogic的REST API,Java API和Node.JS API的用户可以使用转换和补丁。


1
投票

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


0
投票

使用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)
© www.soinside.com 2019 - 2024. All rights reserved.