【发布时间】:2015-06-22 09:29:03
【问题描述】:
示例 XML:
let $xml := document {
<doc>
<p>sample</p>
<categories>
<category>comdey</category>
<category>drama</category>
</categories>
</doc>
}
代码:
let $xsl :=
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1" indent="no"/>
<xsl:template match="category">
<entertainment>
<xsl:apply-templates select="@*|node()"/>
</entertainment>
</xsl:template>
<xsl:template match="categories">
<entertainments>
<xsl:apply-templates select="@*|node()"/>
</entertainments>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
return xdmp:xslt-eval($xsl, $xml)
上述代码可以从 MarkLogic 查询控制台执行,它将“类别”替换为“娱乐”,将“类别”替换为“娱乐”。
但是我们如何将其编写为 MarkLogic xslt 转换,可以使用 REST API 或 Java API 安装并应用于保存在 MarkLogic 中的 xml 文件。
阅读: 通过 JAVA API 创建和安装转换已经实现,并且正在为 MarkLogic 站点中给出的示例内容转换文件工作。
问题是我们不清楚如何将此 xslt 代码转换为 MarkLogic 指定的转换方言。我们确实尝试过转换,但出现了错误(在底部提到)
trail.xslt 代码:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:example="http://marklogic.com/rest-api/transform/trial"
xmlns:map="http://marklogic.com/xdmp/map">
<xsl:param name="context" as="map:map"/>
<xsl:param name="params" as="map:map"/>
<xsl:template match="genre">
<entertainment>
<xsl:apply-templates select="@*|node()"/>
</entertainment>
</xsl:template>
<xsl:template match="genres">
<entertainments>
<xsl:apply-templates select="@*|node()"/>
</entertainments>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我们已将上述代码保存为 trail.xslt 并尝试安装转换但遇到一些错误,错误如下
错误:
HTTP Status 500 - Request processing failed; nested exception is com.marklogic.client.FailedRequestException: Local message: config/transforms write failed: Bad Request. Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000)
Invalid content: invalid trial extension: could not parse XQuery extension trial; please see the server error log for detail XDMP-IMPORTMOD: Cannot import Main Module /marklogic.rest.transform/trial/assets/transform.xqy; trial either is not a valid module or does not provide extension functions (transform) in the http://marklogic.com/rest-api/transform/trial namespace
【问题讨论】: