- From: Norman Walsh <ndw@nwalsh.com>
- Date: Fri, 22 May 2009 08:23:41 -0400
- To: XProc Dev <xproc-dev@w3.org>
- Message-ID: <m2iqjtnx6a.fsf@nwalsh.com>
Pierre LINDENBAUM <plindenbaum@yahoo.fr> writes:
> I'm a new with XPROC. I'm currently tryinhg to send a SOAP request
> to a server using a p:http-request with a custom c:header It worked
> fine when the message was inline:
>
> <p:http-request>
> <p:input port="source">
> <p:inline>
> <c:request method="POST" href="http://example.com" >
> <c:header name="Soapaction" value="http://example.com"/>
> <c:body content-type="application/xml">
> <soap:Envelope>(...)</soap:Envelope>
> </c:body>
> </c:request>
> </p:inline>
> </p:input>
> </p:http-request>
>
> But, now, I would like to send a custom XML document that was build
> elsewhere in the pipeline. How can I achieve this ?
There are a couple of ways. Neither is what you'd call beautiful.
Inserting content into the middle of an XML document turns out to be a
little tricky.
One way is with XSLT:
<p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step">
<p:xslt>
<p:input port="source">
<p:inline>
<c:request method="POST" href="http://example.com" >
<c:header name="Soapaction" value="http://example.com"/>
<c:body content-type="application/xml"/>
</c:request>
</p:inline>
</p:input>
<p:input port="stylesheet">
<p:inline>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" encoding="utf-8" indent="no"
omit-xml-declaration="yes"/>
<xsl:preserve-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="c:body">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="doc('soap.xml')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()|processing-instruction()|text()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
</p:inline>
</p:input>
</p:xslt>
<p:http-request/>
</p:pipeline>
Another, and one that will be easier if you want to make the name of
the file that contains the payload dynamic, is to use a combination of
wrap-sequence and set-attributes:
<p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step">
<p:identity name="headers">
<p:input port="source">
<p:inline>
<c:header name="Soapaction" value="http://example.com"/>
</p:inline>
<p:inline>
<c:header name="Otherheader" value="otherValue"/>
</p:inline>
</p:input>
</p:identity>
<p:load name="payload" href="soap.xml"/>
<p:wrap-sequence wrapper="c:request">
<p:input port="source">
<p:pipe step="headers" port="result"/>
<p:pipe step="payload" port="result"/>
</p:input>
</p:wrap-sequence>
<p:set-attributes match="/c:request">
<p:input port="attributes">
<p:inline>
<irrelevantElementName method="POST" href="http://example.com"/>
</p:inline>
</p:input>
</p:set-attributes>
<p:http-request/>
</p:pipeline>
I hope that helps.
Be seeing you,
norm
--
Norman Walsh <ndw@nwalsh.com> | 5% of the world's population consumes a
http://nwalsh.com/ | third of its resources and makes nearly
| half its waste. That 5% is US.
Received on Friday, 22 May 2009 12:24:23 UTC