XSLT 中的 document() 和 fn:doc() 有什么区别?

por*_*ton 1 xml xslt

XSLTdocument()fn:doc()XSLT 中有什么区别?

Mar*_*nen 6

document函数于 1999 年在 XSLT 1.0中引入具有以下签名:node-set document(object, node-set?),也就是说,它接受一个对象作为第一个参数和一个可选的节点集类型的第二个参数,并返回一个节点集。第一个参数可以是 URI 值的节点集,例如,给定输入<files><file>doc1.xml</file><file>doc2.xml</file><file>doc3.xml</file></files>,调用document(/files/file)返回三个文档节点的并集document('file1.xml') | document('file2.xml') | document('file3.xml')

XSLT和XPath 2.0的进一步发展接合于的XQuery 1.0发展的力和定义共同功能XSLT和XPath 2.0和XQuery 1.0在2007年,它们中的一个是所述doc函数具有以下特征:fn:doc($uri as xs:string?) as document-node()?即该函数采用一个单string 参数和一个 URI 并返回一个文档节点(或者它接受一个空序列作为它的参数并返回一个空序列),所以基本上它加载一个单个 XML 文档,例如doc('file1.xml').

document函数在 XSLT 2.0 中继续可用,并且有签名

document($uri-sequence as item()*) as node()*
document($uri-sequence as item()*, $base-node as node()) as node()*
Run Code Online (Sandbox Code Playgroud)

正如您在链接规范中所见,该doc函数用于解释documentXSLT 2.0 中函数的语义。

此外,该document函数允许在 URI 引用参数中使用片段标识符。

总之,该doc函数允许在 XSLT 和 XPath 2.0 及更高版本以及 XQuery 1.0 及更高版本中解析单个文档,但该document函数更复杂,其使用仅限于 XSLT。