Xproc:将动态href传递给<p:http-request>

时间:2015-04-22 16:07:48

标签: xml xslt xproc

我有一个在输入上运行XSLT的管道,然后通过<p:http-request>步骤将该结果的PUT输入到数据库中。

这里的棘手问题是我需要使用<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中的属性值构建它,并将其提供给我的{{1步骤的href选项。

我尝试添加<c:request>步骤以在<p:attribute match>之前更改href属性,但它没有获取我需要的<p:http-request>/*/@name值:< / p>

/*/@number

1 个答案:

答案 0 :(得分:3)

好吧,我能够弄清楚这一点。

看起来添加<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值需要更新为{ {1}}和/*/*/@name

相关问题