<p:xslt>的馈送输出进入<c:body>Xproc 中的 HTTP PUT 请求 [英] Feeding output of <p:xslt> into <c:body> of HTTP PUT request in Xproc
问题描述
我下面的 Xproc 管道的目标是接收源 XML 文档,使用 <p:xslt>
步骤运行 2 个 XSLT 转换,然后在第二个 之后提供输出 XML<p:xslt>
到
步骤的
:
My goal for my Xproc pipeline below is to take in a source XML document, run 2 XSLT transforms with <p:xslt>
steps, then feed the output XML after the 2nd <p:xslt>
to the <c:body>
of the <p:http-request>
step:
<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" primary="true"/>
<p:output port="result" primary="true"/>
<p:serialization port="result"
indent="false"
method="xml"
encoding="utf-8"
omit-xml-declaration="false"
doctype-system="myDTD.dtd"
doctype-public="-//DOCTYPE-HERE"/>
<p:xslt>
<p:input port="stylesheet">
<p:document href="XSLT-1.xslt"/>
</p:input>
</p:xslt>
<p:xslt>
<p:input port="stylesheet">
<p:document href="XSLT-2.xslt"/>
</p:input>
</p:xslt>
<p:http-request omit-xml-declaration="false"
encoding="UTF-8">
<p:input port="source">
<p:inline>
<c:request href="http://localhost:80/myRESTserver/dburi/myDOC.xml"
auth-method="basic"
username="user"
password="admin"
method="put">
<c:body content-type="text/xml" >
</c:body>
</c:request>
</p:inline>
</p:input>
</p:http-request>
有没有办法实现这一目标?当我尝试按原样执行此代码时,首先调用 <p:http-request>
(将一个空的 XML 文件放入数据库).
Is there a way to achieve this? When I try executing this code as is, the <p:http-request>
is invoked first (PUTS an empty XML file into the database).
推荐答案
p:http-request
首先运行的原因是它不依赖于管道中的任何其他步骤.p:http-request
的source
输入端口绑定到一个静态内联c:request
文档,因此该步骤不需要等待对于任何其他步骤要先完成.因此,该步骤可以随时运行.
The reason why p:http-request
runs first is that it does not depend on any other steps in the pipeline. The source
input port of p:http-request
is bound to a static inline c:request
document and therefore the step does not need to wait for any other steps to finish first. The step can therefore run at any time.
要解决这个问题,您需要将 p:http-request
的输入端口连接到第二个 p:xslt
步骤.这可以显式地(使用p:pipe
)或隐式地完成(依赖于XProc 处理器将自动制造隐含的p:pipe
连接这一事实).让我们在解决您的主要问题(在 c:body
中嵌入 p:xslt
的输出)的同时进行演示:
To fix that, you need to connect the input port of p:http-request
to the second p:xslt
step. This can be done explicitly (using p:pipe
) or implicitly (relying on the fact that the XProc processor will manufacture implied p:pipe
connections automatically). Let's demonstrate both while solving your main question (embedding the output of p:xslt
in c:body
) in the process:
为了在 XML 包装器中嵌入 XML 内容,通常的 XProc 步骤是 p:wrap
和 p:wrap-sequence
.但是,它们使用简单的(一级)XML 包装器元素,因此如果您想包装多级 XML(如您的情况:c:request/c:body
).所以你必须使用其他东西 - 例如 p:insert
步骤:
For embedding XML content in XML wrappers, the usual go-to XProc steps are p:wrap
and p:wrap-sequence
. However, they work with simple (one level) XML wrapper elements, so they are not all that helpful if you want to wrap in multiple levels of XML (as in your case: c:request/c:body
). So you have to use something else - for example the p:insert
step:
...
<p:xslt name="xslt2">
<p:input port="stylesheet">
<p:document href="XSLT-2.xslt"/>
</p:input>
</p:xslt>
<p:insert match="c:request/c:body" position="first-child">
<p:input port="source">
<p:inline>
<c:request href="http://localhost:80/myRESTserver/dburi/myDOC.xml"
auth-method="basic"
username="user"
password="admin"
method="put">
<c:body content-type="text/xml">
</c:body>
</c:request>
</p:inline>
</p:input>
<p:input port="insertion">
<p:pipe step="xslt2" port="result"/>
</p:input>
</p:insert>
<p:http-request omit-xml-declaration="false"
encoding="UTF-8"/>
...
让我们看看它的作用:
- 我们为第二个
p:xslt
步骤命名(xslt2
). - 我们在第二个
p:xslt
步骤和p:http-request
步骤之间放置了一个p:identity
步骤.p:identity
步骤使用静态c:request/c:body
文档作为插入目标,并将名为xslt2
的步骤的输出作为要插入的内容.它将内容作为c:request/c:body
的第一个子元素插入. - 我们从
p:http-request
的source
输入端口移除了静态连接.这很好,因为p:insert
步骤的输出会自动流入p:http-request
的source
输入端口.立>
- We gave the second
p:xslt
step a name (xslt2
). - We placed an
p:identity
step in between the secondp:xslt
step and thep:http-request
step. Thep:identity
step uses a staticc:request/c:body
document as the insertion target and the output of the step namedxslt2
as the content to be inserted. It inserts the content as the first child ofc:request/c:body
. - We removed the static connection from the
source
input port of thep:http-request
. This is fine because the output of thep:insert
step will flow into thesource
input port ofp:http-request
automatically.
这篇关于<p:xslt>的馈送输出进入<c:body>Xproc 中的 HTTP PUT 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!