我有一个管道,它在输入上运行一个XSLT,然后通过<p:http-request>步骤将结果放入数据库。
这里的棘手之处在于,我需要使用来自<p:xslt> XML输出的元数据构建一个动态href。
下面是我想要实现的伪代码:
<p:xslt name="XSLT1">
<p:input port="stylesheet">
<p:document href="XSLT-1.xslt" />
</p:input>
</p:xslt>
<p:variable name="href" select="concat('http://localhost:8000/myRESTendpoint?uri=/mydb/', /*/@name, /*/@number,'.xml')"/>
<p:sink />
<p:insert position="first-child" match="c:body">
<p:input port="source">
<p:inline>
<c:request
href="{$href}"
auth-method="basic"
username="user"
password="pw"
method="put">
<c:body content-type="text/xml" >
</c:body>
</c:request>
</p:inline>
</p:input>
<p:input port="insertion">
<p:pipe step="XSLT1" port="result" />
</p:input>
</p:insert>
<p:http-request omit-xml-declaration="false" encoding="UTF-8">
<p:input port="source"/>
</p:http-request>正如您在<p:variable>步骤中看到的,我正在尝试构建一个字符串,并使用来自<p:xslt>步骤的输出XML的属性值构造它,并将其提供给我的<c:request>步骤的href选项。
我尝试添加一个<p:attribute match>步骤来更改<p:http-request>之前的href属性,但它没有获取我需要的/*/@name和/*/@number值:
<p:add-attribute match="/c:request" attribute-name="href">
<p:with-option name="attribute-value" select="concat('http://localhost:8000/myRESTendpoint?uri=/mydb/', /*/@name, /*/@number,'.xml')"/>
</p:add-attribute>发布于 2015-04-23 00:39:43
好的,我能够弄明白这一点。
看起来添加一个<p:add-attribute>步骤是正确的方法,这里的问题只是我的Xpath中的一个错误...
<p:with-option name="attribute-value" select="concat('http://localhost:8000/myRESTendpoint?uri=/mydb/', /*/*/@name, /*/*/@number,'.xml')"/>由于PUT主体被包装在一个元素中,我需要再往下一层才能到达XML文档(XSLT1输出)的根元素处所需的元数据,因此需要将我的XPath值更新为/*/*/@name和/*/*/@number。
https://stackoverflow.com/questions/29803188
复制相似问题