【发布时间】:2016-06-24 13:42:36
【问题描述】:
我正在研究用于数据连接和转换为其他数据结构的 noSQL 解决方案 - 特别是在 marklogic 和 couchbase 中。
我的问题:如何在基于 json 的数据库中进行 xslt 之类的转换?
【问题讨论】:
-
MarkLogic 8 也存储原生 JSON。但是这个问题不符合 SO 准则,所以我怀疑它会被关闭。
我正在研究用于数据连接和转换为其他数据结构的 noSQL 解决方案 - 特别是在 marklogic 和 couchbase 中。
我的问题:如何在基于 json 的数据库中进行 xslt 之类的转换?
【问题讨论】:
我对 CouchBase 还不够熟悉,无法评论它的功能。
MarkLogic 允许通过REST PATCH requests 使用 XPath 或 JSONPath 进行简单的转换。我不会称它为“像 xslt”,但它绝对是一种更新 JSON 文档特定部分的方法。此外,MarkLogic 允许 server-side transformations written in Javascript 如果这更符合您的风格。 MarkLogic 的 REST API、Java API 和 Node.JS API 的用户可以使用转换和补丁。
【讨论】:
此外,MarkLogic 支持 SPARQL,它可以执行 RDF 转换,如果这是选择的数据格式,并且可以以 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">
"ParentName":<xsl:if test='$childName = json:children/json:json/json:name/text()'>"<xsl:value-of select="json:name/text()"/>"</xsl:if>
</xsl:template>
</xsl:stylesheet>
return xdmp:document-insert("/templates.xsl",$xslt)
【讨论】: