通过为<sch:ns/>
和cts
声明适当的dohickey
,我可以按如下方式从编译的Schematron调用MarkLogic API函数,例如cts:*
(顺便说一下,这是awesome:
<sch:rule context="dohickey:thingummy">
<sch:let name="this-id" value="dohickey:meta/dohickey:id/string()"/>
<sch:let name="known-ids" value="cts:element-values(xs:QName('dohickey:id'))"/>
<sch:report test="$this-id = $known-ids">Warning: This id is known, and that's a business error</sch:report>
</sch:rule>
((请忽略$known-ids
变量将被优化为在现实生活中锁定单个值,而不是全部返回它们-为方便示例,]
现在,我希望以与上面示例中调用cts:*
相同的方式在Schematron中包含自定义XQuery模块,并且以与在使用原始XSLT和MarkLogic XSLT时可以调用XQuery库函数相同的方式/ XQuery集成,方法是定义例如xsl:stylesheet/@extension-element-prefixes
值,然后定义适当的<xdmp:import-module/>
。
示例:我想执行以下操作:
<sch:rule context="dohickey:thingummy">
<sch:let name="this-id" value="dohickey:meta/dohickey:id/string()"/>
<sch:let name="is-flagged-for-revision" value="mycustommodule:is-flagged-for-revision($this-id)"/>
<sch:report test="$is-flagged-for-revision">Warning: This id has been flagged for revision</sch:report>
</sch:rule>
问题:当前是否有一种方法可以使MarkLogic的schematron:put
编译行为包括自定义XQuery模块导入,类似于MarkLogic的XSLT <xdmp:import-module/>
支持?还是应该只实现一个包装器,将schematron:put
编译结果转换为包含我需要的包装,以便将其包含在已编译的XSLT中?
正如您自己提到的那样,可以使用<xdmp:import-module>
指令将XQuery库模块导入MarkLogic中的XSLT样式表。导入模块后,该样式表即可使用该模块中定义的所有功能。
可以在您的Schematron模式中合并外来词汇。您可以使用它在编译模式中包含<xdmp:import-module>
。但是,编译Schematron时需要将xdmp:import-module
参数设置为allow-foreign
。默认值为allow-foreign
。
在Schematron模式中,您首先需要使用true
声明名称空间,以便识别前缀:
false
您添加外部标记,例如sch:ns
,以导入XQuery库模块。将导入置于架构的根级别:
<sch:ns prefix="search" uri="http://marklogic.com/appservices/search"/>
<sch:ns prefix="xdmp" uri="http://marklogic.com/xdmp"/>
您可以使用前面定义的前缀直接在Schematron中使用导入的库函数:
xdmp:import-module
只要确保将Schematron模式编译为XSLT,然后使用<xdmp:import-module namespace="http://marklogic.com/appservices/search"
href="/MarkLogic/appservices/search/search.xqy"/>
将其加载到模块数据库中,就可以将<sch:rule context="test">
<sch:let name="estimate" value="search:estimate(search:parse(@term))"/>
<sch:assert test="$estimate gt 0" diagnostics="d1">At least one doc should be found</sch:assert>
</sch:rule>
选项设置为schematron:put()
,如下所示:
schematron:put()