我有一个管道,它在输入上运行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>
步骤来更改 href <p:http-request>
属性,但它没有获取我需要的/*/@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>
我能够弄清楚这一点。
看起来添加一个<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
。