XProc 1.0 中 <p:filter> 的序列输入?
Sequence input to <p:filter> in XProc 1.0?
XProc 中的 <p:filter>
是否能够接受一系列文档作为输入?当我喂 Calabash 时:
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step"
version="1.0">
<p:input port="source" sequence="true">
<p:inline>
<doc>
<content>Hello world!</content>
</doc>
</p:inline>
<p:inline>
<doc>
<content>Goodbye world!</content>
</doc>
</p:inline>
</p:input>
<p:output port="result" sequence="true"/>
<p:filter select="//content">
<p:input port="source" sequence="true"/>
</p:filter>
</p:declare-step>
它引发了以下错误:
err:XD0006 : 2 documents appear on the 'source' port. If sequence is not specified, or has the value false, then it is a dynamic error unless exactly one document appears on the declared port.
@sequence
是 指定的,并且值为 "true"。如果我从输入中删除第二个内联文档,则处理会成功完成。如果我保留两个输入,但将 <p:filter>
替换为接受序列的其他内容,例如 <p:count>
,它也会成功运行到完成。
我很困惑,因为错误消息没有说 <p:filter>
不能接受序列;它告诉我指定一个序列,我已经做到了。并且由于 XPath 过滤可以应用于 XPath collection()
函数,所以不清楚(对我来说)为什么不应该过滤 XProc 中的一系列文档,至少原则上是这样。
我也不确定如何阅读规范,其中关于 <p:filter>
说:
This step behaves just like an p:input with a select expression except that the
select expression is computed dynamically.
因为 <p:input>
可以接受一个序列,如果据说 <p:filter>
除了过滤之外的行为方式相同,那似乎意味着 <p:filter>
也应该能够接受一个顺序。
我认为选项是:
<p:filter>
接受多个输入,但我没有正确指定。
<p:filter>
不接受多个输入,错误消息和规范具有误导性,或者我未能正确理解它们。
我很高兴(好吧,愿意)承认用户在这两种情况下的错误,但我会很感激你的澄清。
是的,我可以通过使用 <p:wrap-sequence>
将多个输入形成一个 XML 树来解决这个问题,但我的问题是 <p:filter>
是如何工作的,并且而不是关于如何获得特定结果的结果。在我的实际代码中,读取和传递我的真实输入文档需要 1.5 秒,如果我添加包装它们的步骤则需要 4.5 秒,我想节省 3 秒,特别是因为包装将是一个短暂的工作 -周围,因为我只是要提取内容并在过滤步骤后最终得到多个文档。
根据 XProc 语言的推荐,阅读 7.1.9 p:filter 处的以下步骤定义:
<p:declare-step type="p:filter">
<p:input port="source"/>
<p:output port="result" sequence="true"/>
<p:option name="select" required="true"/> <!-- XPathExpression -->
</p:declare-step>
您可以注意到 source 端口未使用 sequence="true"
声明,因此您上面提到的第二个选项是正确的。
作为解决方法,您确实可以使用 <p:wrap>
.
XProc 中的 <p:filter>
是否能够接受一系列文档作为输入?当我喂 Calabash 时:
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step"
version="1.0">
<p:input port="source" sequence="true">
<p:inline>
<doc>
<content>Hello world!</content>
</doc>
</p:inline>
<p:inline>
<doc>
<content>Goodbye world!</content>
</doc>
</p:inline>
</p:input>
<p:output port="result" sequence="true"/>
<p:filter select="//content">
<p:input port="source" sequence="true"/>
</p:filter>
</p:declare-step>
它引发了以下错误:
err:XD0006 : 2 documents appear on the 'source' port. If sequence is not specified, or has the value false, then it is a dynamic error unless exactly one document appears on the declared port.
@sequence
是 指定的,并且值为 "true"。如果我从输入中删除第二个内联文档,则处理会成功完成。如果我保留两个输入,但将 <p:filter>
替换为接受序列的其他内容,例如 <p:count>
,它也会成功运行到完成。
我很困惑,因为错误消息没有说 <p:filter>
不能接受序列;它告诉我指定一个序列,我已经做到了。并且由于 XPath 过滤可以应用于 XPath collection()
函数,所以不清楚(对我来说)为什么不应该过滤 XProc 中的一系列文档,至少原则上是这样。
我也不确定如何阅读规范,其中关于 <p:filter>
说:
This step behaves just like an p:input with a select expression except that the select expression is computed dynamically.
因为 <p:input>
可以接受一个序列,如果据说 <p:filter>
除了过滤之外的行为方式相同,那似乎意味着 <p:filter>
也应该能够接受一个顺序。
我认为选项是:
<p:filter>
接受多个输入,但我没有正确指定。<p:filter>
不接受多个输入,错误消息和规范具有误导性,或者我未能正确理解它们。
我很高兴(好吧,愿意)承认用户在这两种情况下的错误,但我会很感激你的澄清。
是的,我可以通过使用 <p:wrap-sequence>
将多个输入形成一个 XML 树来解决这个问题,但我的问题是 <p:filter>
是如何工作的,并且而不是关于如何获得特定结果的结果。在我的实际代码中,读取和传递我的真实输入文档需要 1.5 秒,如果我添加包装它们的步骤则需要 4.5 秒,我想节省 3 秒,特别是因为包装将是一个短暂的工作 -周围,因为我只是要提取内容并在过滤步骤后最终得到多个文档。
根据 XProc 语言的推荐,阅读 7.1.9 p:filter 处的以下步骤定义:
<p:declare-step type="p:filter"> <p:input port="source"/> <p:output port="result" sequence="true"/> <p:option name="select" required="true"/> <!-- XPathExpression --> </p:declare-step>
您可以注意到 source 端口未使用 sequence="true"
声明,因此您上面提到的第二个选项是正确的。
作为解决方法,您确实可以使用 <p:wrap>
.