User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the RSS, Web Services and SOAP section within the Web Development category of DaniWeb, a massive community of 329,240 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,382 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our RSS, Web Services and SOAP advertiser:
Views: 526 | Replies: 2
Reply
Join Date: Mar 2008
Posts: 3
Reputation: ramabahama is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ramabahama ramabahama is offline Offline
Newbie Poster

Trouble with SOAP and xslt

  #1  
Mar 21st, 2008
I'm trying to run a SOAP response from a web service through an xslt translation and place it in a web page via an Ajax call. The web service and javascript all works fine. I am having a problem accessing specific nodes inside the xslt file.

Specifically: when I run the SOAP response through <xsl:for-each select="//*"> I can get all the correct node names in the response and their associated values. However when I try to access via <xsl:for-each select="//getStringResult"> I get absolutely nothing.

Here's an example of the SOAP response
<?xml version="1.0" encoding="utf-i"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<getStringResponse xmlns="http://ramabahama.net/webservices">
<getStringResult>
<Salutation>String value as expected</Salutation>
<Id>Integer as expected</Id>
</getStringResult>
</getStringResponse>
</soap:Body>
</soap:Envelope>

Here's the xslt file
<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" indent="yes" media-type="text/html" />
	<xsl:template match="/">
		<table border="2px" cellspacing="10px">
			<xsl:for-each select="//*">
				<tr>
					<td style="border: solid thin green; padding: 10px; text-align: left; vertical-align: middle;">
						<xsl:value-of select="current()" />
					</td>
					<td style="border: solid thin green; padding: 10px; text-align: left; vertical-align: middle;">
						<xsl:value-of select="name()" />
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>
</xsl:stylesheet>

Any idea why I'm having problems with my XPath usage? Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 3
Reputation: ramabahama is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ramabahama ramabahama is offline Offline
Newbie Poster

Re: Trouble with SOAP and xslt

  #2  
Mar 22nd, 2008
Okay, maybe if I show the supporting javascript:
  1. function callService() {
  2. var _IE = (new RegExp('internet explorer', 'gi')).test(navigator.appName);
  3. if(_IE) {
  4. xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
  5. xmlObj = new ActiveXObject('MSXML2.FreeThreadedDOMDocument.3.0');
  6. xslObj = new ActiveXObject('MSXML2.FreeThreadedDOMDocument.3.0');
  7. } else {
  8. xmlReq =new XMLHttpRequest();
  9. xslObjProcessor = new XSLTProcessor();
  10. }
  11. var soapReq = '<?xml version="1.0" encoding="utf-8"?>' +
  12. '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
  13. ' <soap:Body>' +
  14. ' <getString xmlns="http://ramabahama.net/webservices">' +
  15. ' <name_in>Bubbly Boobbah</name_in>' +
  16. ' </getString>' +
  17. ' </soap:Body>' +
  18. '</soap:Envelope>';
  19. xmlReq.open('POST', 'http://127.0.0.1/(S(<%=Session.SessionID%>))/webservices/test1/test1.cs.asmx', false);
  20. xmlReq.setRequestHeader('SOAPAction', 'http://ramabahama.net/webservices/getString');
  21. xmlReq.setRequestHeader('Content-Type', 'text/xml');
  22. xmlReq.send(soapReq);
  23. if(xmlReq.status == '200') {
  24. document.getElementById('ServiceDisplay').innerHTML = '';
  25. var xmlResponseXML = xmlReq.responseXML;
  26. var xmlResponseText = xmlReq.responseText;
  27. xmlReq.open('GET', 'http://127.0.0.1/ARIS/products/test1.xslt', false);
  28. xmlReq.send(null);
  29. if(xmlReq.status == '200') {
  30. var xmlHttp;
  31. var xmlReq;
  32. var xslObj;
  33. var xslObjProcessor;
  34. var xmlObj;
  35. if(_IE) {
  36. xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  37. xmlObj = new ActiveXObject('MSXML2.FreeThreadedDOMDocument.3.0');
  38. xslObj = new ActiveXObject('MSXML2.FreeThreadedDOMDocument.3.0');
  39. xmlObj.async = false;
  40. xslObj.async = false;
  41. var xslTemplateObj = new ActiveXObject('MSXML2.XSLTemplate.3.0');
  42. xslObj.loadXML(xmlReq.responseText);
  43. xslTemplateObj.stylesheet = xslObj;
  44. xslObjProcessor = xslTemplateObj.createProcessor();
  45. xslObjProcessor.input = xmlResponseXML;
  46. xslObjProcessor.transform();
  47. document.getElementById('ServiceDisplay').innerHTML = xslObjProcessor.output;
  48. } else {
  49. var objParser = new DOMParser();
  50. xslObjProcessor = new XSLTProcessor();
  51. xmlObj = xmlResponseXML;
  52. xslObj = xmlReq.responseXML;
  53. xslObjProcessor.importStylesheet(xslObj);
  54. document.getElementById('ServiceDisplay').appendChild(xslObjProcessor.transformToFragment(xmlObj, document));
  55. }
  56. alert(xmlResponseText);
  57. alert(xmlReq.responseText);
  58. alert(document.getElementById('ServiceDisplay').innerHTML);
  59. } else {
  60. alert('Error: ' + xmlReq.status);
  61. }
  62. } else {
  63. document.getElementById('ServiceDisplay').innerHTML = '<span style="color: red; font-weight: bold;">There wuz an error.</span>';
  64. }
  65. }

The only function that is called is 'callService'. That function makes the web service call and then retrieves the xslt file. Both of these are done via Ajax.

I'm sure I'm missing something pretty damned basic .. but I could really use some help.

Thanks.
Reply With Quote  
Join Date: Mar 2008
Posts: 3
Reputation: ramabahama is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ramabahama ramabahama is offline Offline
Newbie Poster

Re: Trouble with SOAP and xslt

  #3  
Mar 22nd, 2008
Found the answer. I was not defining the namespace for 'soap:' and thus the xslt translator couldn't find 'soap:Envelope' or 'soap:Body' tags. On top of that I had to set up a namespace for the 'http://ramabahama.net/webservices' name space. I used 'roas' and once I included xmlns:roas=http://ramabahama.net/webservices' to the xsl:stylesheet tag I could reference the returned values as 'roas:[fill in tag name here]'.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Other Threads in the RSS, Web Services and SOAP Forum

All times are GMT -4. The time now is 11:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC