fn:transform 运行 默认调用模板调用 - 未创建结果文档
fn:transform running with default call-template invocation - no result-documents created
此转换 test.xsl 通过为每个递归遇到的 XML 文件调用身份转换来复制(为了一个小测试示例的目的)XML 数据的目录。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
version="3.0" exclude-result-prefixes="xsi fn xs map" expand-text="yes">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="currentStylesheet" as="document-node()" select="doc('identity.xsl')"/>
<xsl:template name="xsl:initial-template">
<xsl:for-each select="collection('file:///mnt/c/home/oneD/data/translatable' || '?select=*.xml;recurse=yes')">
<xsl:result-document href="{replace(document-uri(),'/data/translatable/','/translated/')}">
<xsl:sequence select=" fn:transform(map {
'stylesheet-node' : $currentStylesheet,
'source-node' : .
})?output"/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
但是,如果我像这样使用 fn:transform 从 XQuery 调用它
xquery version "3.1";
fn:transform(map { 'stylesheet-node' : doc('test.xsl')})?output
none 个结果文档已创建。
调用XQuery有问题吗?我以前从未尝试过这个,所以这是我阅读文档的最佳尝试。 运行 撒克逊 10.3
fn:transform
function 不会向文件系统写入任何内容,它 returns 映射
one entry in the map for the principal result document, and one for
each secondary result document. The key is a URI in the form of an
xs:string value. The key for the principal result document is the base
output URI if specified, or the string "output" otherwise. The key for
secondary result documents is the URI of the document, as an absolute
URI. The associated value in each entry depends on the requested
delivery format. If the delivery format is document, the value is a
document node. If the delivery format is serialized, the value is a
string containing the serialized result
如果您想将结果文档写入文件系统,您需要在处理由 transform
函数返回的映射的代码中执行此操作,例如使用 fn:put
或 EXPath file
模块。
transform
函数的选项映射也有一个钩子post-process
:
A function that is used to post-process each result document of the
transformation (both the principal result and secondary results), in
whatever form it would otherwise be delivered (document, serialized,
or raw). The first argument of the function is the key used to
identify the result in the map return by the fn:transform function
(for example, this will be the supplied base output URI in the case of
the principal result, or the string "output" if no base output URI was
supplied). The second argument is the actual value. The value that is
returned in the result of the fn:transform function is the result of
applying this post-processing.
请注意,Saxonica 的开源家庭版不提供 fn:put
和 EXPath 文件模块;虽然 GitHub 上有第三方 file
模块实现:https://github.com/Armatiek/saxon-extensions
此转换 test.xsl 通过为每个递归遇到的 XML 文件调用身份转换来复制(为了一个小测试示例的目的)XML 数据的目录。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
version="3.0" exclude-result-prefixes="xsi fn xs map" expand-text="yes">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="currentStylesheet" as="document-node()" select="doc('identity.xsl')"/>
<xsl:template name="xsl:initial-template">
<xsl:for-each select="collection('file:///mnt/c/home/oneD/data/translatable' || '?select=*.xml;recurse=yes')">
<xsl:result-document href="{replace(document-uri(),'/data/translatable/','/translated/')}">
<xsl:sequence select=" fn:transform(map {
'stylesheet-node' : $currentStylesheet,
'source-node' : .
})?output"/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
但是,如果我像这样使用 fn:transform 从 XQuery 调用它
xquery version "3.1";
fn:transform(map { 'stylesheet-node' : doc('test.xsl')})?output
none 个结果文档已创建。
调用XQuery有问题吗?我以前从未尝试过这个,所以这是我阅读文档的最佳尝试。 运行 撒克逊 10.3
fn:transform
function 不会向文件系统写入任何内容,它 returns 映射
one entry in the map for the principal result document, and one for each secondary result document. The key is a URI in the form of an xs:string value. The key for the principal result document is the base output URI if specified, or the string "output" otherwise. The key for secondary result documents is the URI of the document, as an absolute URI. The associated value in each entry depends on the requested delivery format. If the delivery format is document, the value is a document node. If the delivery format is serialized, the value is a string containing the serialized result
如果您想将结果文档写入文件系统,您需要在处理由 transform
函数返回的映射的代码中执行此操作,例如使用 fn:put
或 EXPath file
模块。
transform
函数的选项映射也有一个钩子post-process
:
A function that is used to post-process each result document of the transformation (both the principal result and secondary results), in whatever form it would otherwise be delivered (document, serialized, or raw). The first argument of the function is the key used to identify the result in the map return by the fn:transform function (for example, this will be the supplied base output URI in the case of the principal result, or the string "output" if no base output URI was supplied). The second argument is the actual value. The value that is returned in the result of the fn:transform function is the result of applying this post-processing.
请注意,Saxonica 的开源家庭版不提供 fn:put
和 EXPath 文件模块;虽然 GitHub 上有第三方 file
模块实现:https://github.com/Armatiek/saxon-extensions