web service call: curl output to xsltproc input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting web service call: curl output to xsltproc input
# 1  
Old 07-15-2011
web service call: curl output to xsltproc input

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...
Code:
xsltproc stylesheet xml-file

If I used the same trick to supply the XML-file contents to xsltproc via stdin, that works (see below):
Code:
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
Code:
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):
Code:
<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
Code:
<?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

Last edited by webuser; 07-16-2011 at 12:10 AM.. Reason: incorrect code
# 2  
Old 07-15-2011
Why can you not hardcode in the name of the stylesheet?

Oh, and by the way, your stylesheet is incorrect. Compare the output of your stylesheet and the following stylesheet
Code:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                              xmlns:ns2="http://server/webservices/operations/schema">

   <xsl:output method="text" />

   <xsl:template match='soapenv:Envelope'>
       <xsl:apply-templates select="soapenv:Body"/>
   </xsl:template>

   <xsl:template match='soapenv:Body'>
       <xsl:apply-templates select="ns2:HolidayResponse"/>
   </xsl:template>

   <xsl:template match='ns2:HolidayResponse'>
       <xsl:apply-templates select="ns2:Status"/>
   </xsl:template>

   <xsl:template match='ns2:Status'>
      <xsl:value-of select="." />
   </xsl:template>


</xsl:stylesheet>

# 3  
Old 07-16-2011
curl and xsltproc

I don't want to maintain a separate file for the stylesheet, if I can help it. And the stylesheet I posted works -- this is straight from working code.

Thanks.
# 4  
Old 07-16-2011
Quote:
And the stylesheet I posted works -- this is straight from working code.
Yes it works - but only by accident. Your stylesheet ignores namespaces. Have you compared the output from each?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

CurL command Rest API call with oauth 2.0 secutity error

Hi I need to get rates for different security form REST API . the API is oauth 2.0 secured. i need to use curl command to get json response from api . token URL - is HTTP data URL is - HTTPS when trigger my command from bash script it passing and failing intermittently with... (0 Replies)
Discussion started by: shobhit.working
0 Replies

2. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

3. Linux

Curl login to web page

Hello dears, I am trying to log in the website using curl but no luck so far. The web page Content-Type is : text/html;charset=ISO-8859-1 I try the following command using curl: curl \ --header "Content-type: text/html" \ --request POST \ --data '{"user": "someusername",... (0 Replies)
Discussion started by: Vit0_Corleone
0 Replies

4. UNIX for Beginners Questions & Answers

How to use cURL to download web page with authentification (form)?

Hello, I'm new in the forum and really beginer, and also sorry form my bad english. I use linux and want to create little program to download automaticaly some pdf (invoices) and put in a folder of my computer. I learn how to do and programme with ubuntu but the program will be implemented... (1 Reply)
Discussion started by: MarcelOrMittal
1 Replies

5. UNIX for Dummies Questions & Answers

Curl --cert to call a servlet

Hi, For one of our requirements, we are using curl command from a Linux box to call the servlet using PEM certificates type. Once servlet is trigger, the data will be loaded through servlet. If the servlet thread is completed successfully, then the control should return to Unix and based on... (0 Replies)
Discussion started by: subhransun
0 Replies

6. Shell Programming and Scripting

How to call perl web service from javascript?

Hi, I would like to call the below perl web service from javascript .Any help would be appreciated.I am new to web services.Please do the needful. Server Program(Perl Web Service) #!/usr/bin/perl use lib '/usr/lib/perl5/5.8.8/SOAP-Lite-0.65_3/lib'; use SOAP::Transport::HTTP; use Demo;... (3 Replies)
Discussion started by: liyakathali
3 Replies

7. Shell Programming and Scripting

Call web service from Shell

Hello All, I have to import data from xml file to mysql database multi-time a day. I think it is better to write a tool to help this. So I write a web service in php. I don't know that if we can call a web service via shell script. If it can, I think we can create a cron job to help run it... (2 Replies)
Discussion started by: hapytran
2 Replies

8. UNIX for Dummies Questions & Answers

curl command with web pages

I can't quite seem to understand what the curl command does with a web address. I tried this: curl O'Reilly Media: Tech Books, Conferences, Courses, News but I just got the first few lines of a web page, and it's nowhere on my machine. Can someone elaborate? (2 Replies)
Discussion started by: Straitsfan
2 Replies

9. Shell Programming and Scripting

How to call a web service using perl

Hello to all, What i would like to know is how to call a web service using perl. Where can i find documentation that easy describes this procedure? Any advices will be more tha welcome. Thank you. Best Regards, Chriss_58 (3 Replies)
Discussion started by: chriss_58
3 Replies

10. UNIX for Dummies Questions & Answers

Need to Call Web Service from Unix

I'm a Unix and C programming newbie, and I've been tasked with calling a web service from a legacy Unix app... I've come across libxml2 and libsoup, gnome's libraries for XML/SOAP processing... But I'm seeking guidance on the development process... :o (0 Replies)
Discussion started by: jahooper
0 Replies
Login or Register to Ask a Question