I need to invoke a web service and extract what I need from the response using a combination of curl and xsltproc. However, any file-based parameters that must be supplied to both these programs must be from stdin and not actual files.
At least with curl, it seems to think that I am supplying a file with the "--data @" parameter, while what I am actually doing is supplying the contents of the expected file via standard input (by placing a hyphen next to the @ symbol). With xsltproc, it is a little more tricky because the syntax is...
xsltproc stylesheet xml-file
If I used the same trick to supply the XML-file contents to xsltproc via stdin, that works (see below):
xsltproc remove-soap-envelope.xslt - <<EOF
... // XML response
EOF
...but I don't know how to specify the stylesheet via stdin.
Below are all the relevant details.
The following Bash script sends a SOAP request via curl.
holidayrequest.sh
ENDPOINT="http://server/webservices/operations-ws"
startDate="2011-06-30"
duration=3
curl --silent --user-agent "" --data @- --header "Content-Type: text/xml; charset=UTF-8" ${ENDPOINT} <<EOF
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://server.com/webservices/operations/schema">
<soapenv:Header/>
<soapenv:Body>
<sch:HolidayRequest>
<sch:Duration>${duration}</sch:Duration>
<sch:StartDate>${startDate}</sch:StartDate>
</sch:HolidayRequest>
</soapenv:Body>
</soapenv:Envelope>
EOF
The following [sample] SOAP response is received by stdout (formatted for clarity):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://server/webservices/operations/schema">
<soapenv:Header />
<soapenv:Body>
<ns2:HolidayResponse>
<ns2:Status>Approved</ns2:Status>
</ns2:HolidayResponse>
</soapenv:Body>
</soapenv:Envelope>
(I saved the above response to output.xml and transformed it using an XSLT stylesheet remove-soap-envelope.xslt and xsltproc; "Approved" prints to stdout.)
remove-soap-envelope.xslt
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match='//Status'>
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
A push in the right direction will be much appreciated!
Thanks.
Ashwin