XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 17 Apr 2006 12:07 PM
Hi All,

My XSL looks like following, I am calling Web Service method , which is returning me some plain HTML from screen scrapping. and I am using VB Script to make a call to web service from my XSLT. now I want to write something generic so I don't need to write any kind of script. Is there anyway I can call WebService method directly and get HTML from the method by passing parameter to web service method in XSLT itself.

Following is XSLT looks like

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:abcScripts="http://" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<!-- Include Elements
-->
---
---
Function GetSomeHTML(url)
dim wsURL
wsURL = "http://localhost/abc/so/WebService.asmx/GetHTML"
dim xmlHttpObj
set xmlHttpObj = CreateObject("MSXML2.SERVERXMLHTTP")
xmlHttpObj.open "POST" , wsURL , false
xmlHttpObj.setRequestHeader "Content-Type" , "application/x-www-form-urlencoded"
xmlHttpObj.send "strURL=" & url
GetSomeHTML= xmlHttpObj.responseXML.documentElement.text
End Function
---
---
<xsl:when test="$navid='123'">
<xsl:value-of select="abcScripts:GetSomeHTML('http://localhost/abc/1/123.aspx')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="abcScripts:GetSomeHTML('http://localhost/xyz/1/456.aspx')" />
</xsl:otherwise>

Postnext
Ivan PedruzziSubject: Calling Web Service Method from XSLT .
Author: Ivan Pedruzzi
Date: 17 Apr 2006 01:43 PM

If your web service returns a well formed document and supports HTTP GET just use the document function.

<xsl:value-of select="document('http://localhost/abc/1/123.aspx ... ')"/>

There is no built-in support for HTTP POST in XSLT.

Ivan Pedruzzi
Stylus Studio Team

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 17 Apr 2006 03:20 PM
Thanks for reply, as you suggested I am doing following but still I am getting transformation error.

<xsl:variable name="webServiceURL">
<xsl:text>http://localhost/abc/WebService.asmx/GetHTML?strURL=</xsl:text>
<xsl:text>http://www.yahoo.com</xsl:text>
</xsl:variable>

<xsl:value-of select="document($webServiceURL)/>

My xsl is not right somewhere, I couldn't figure it out , I want to send URL as a parameter to my webservice method.

Postnext
Ivan PedruzziSubject: Calling Web Service Method from XSLT .
Author: Ivan Pedruzzi
Date: 17 Apr 2006 03:37 PM
Try the following

<xsl:variable name="ws" select="'http://localhost/abc/WebService.asmx/GetHTML?strURL='"/>
<xsl:variable name="url" select="'http://www.yahoo.com'"/>

<xsl:value-of select="document(concat($ws, $url))"/>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 17 Apr 2006 03:56 PM
Thanks Ivan

I tried but I am getting following error,

"The Stylesheet doesn't contain a document element. The Stylesheet may be empty or it may not be well formed XML document "

Postnext
Ivan PedruzziSubject: Calling Web Service Method from XSLT .
Author: Ivan Pedruzzi
Date: 17 Apr 2006 05:12 PM

Post the entire stylesheet so can see what you are doing wrong.

Ivan Pedruzzi
Stylus Studio Team

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 18 Apr 2006 10:24 AM
here is my XSL

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;</xsl:text><xsl:text>&#xA;</xsl:text>

<xsl:element name="html"><xsl:text>&#xA;</xsl:text>
<xsl:element name="head"><xsl:text>&#xA;</xsl:text>
<xsl:element name="title"><xsl:text disable-output-escaping="yes">asdasdasd</xsl:text></xsl:element><xsl:text>&#xA;</xsl:text>

<xsl:element name="META">
<xsl:attribute name="NAME">description</xsl:attribute>
<xsl:attribute name="CONTENT"><xsl:text>abc</xsl:text></xsl:attribute>
</xsl:element><xsl:text>&#xA;</xsl:text>
<xsl:element name="META">
<xsl:attribute name="NAME">keywords</xsl:attribute>
<xsl:attribute name="CONTENT"><xsl:text>xyz</xsl:text></xsl:attribute>
</xsl:element><xsl:text>&#xA;</xsl:text>

<xsl:call-template name="links" />
</xsl:element><xsl:text>&#xA;</xsl:text>

<!-- Body -->
<xsl:element name="body">
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates select="data" />
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element>
</xsl:template>

<xsl:template match="data">
<!-- Top Story -->
<xsl:element name="table">
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="cellpadding">0</xsl:attribute>
<xsl:attribute name="cellspacing">0</xsl:attribute>
<xsl:attribute name="width">776</xsl:attribute>
<xsl:attribute name="style">TABLE-LAYOUT: fixed;</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
<xsl:element name="tr">
<xsl:text>&#xA;</xsl:text>
<xsl:element name="td">
<xsl:text>&#xA;</xsl:text>
<xsl:element name="table">
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="cellpadding">0</xsl:attribute>
<xsl:attribute name="cellspacing">0</xsl:attribute>
<xsl:attribute name="height">220</xsl:attribute>
<xsl:attribute name="width">776</xsl:attribute>
<xsl:attribute name="style">border-bottom: solid 4px #003366; TABLE-LAYOUT: fixed;</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
<xsl:element name="tr">
<xsl:text>&#xA;</xsl:text>
<xsl:element name="td">
<xsl:attribute name="height">220</xsl:attribute>
<xsl:attribute name="valign">top</xsl:attribute>
<xsl:attribute name="width">561</xsl:attribute>
<xsl:text>&#xA;</xsl:text>

</xsl:element>
<xsl:element name="td">
<xsl:attribute name="width">215</xsl:attribute>
<xsl:attribute name="valign">top</xsl:attribute>
<xsl:attribute name="style">border-top: solid 4px #003366;</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
<xsl:element name="tr">
<xsl:text>&#xA;</xsl:text>
<xsl:element name="td">
<xsl:attribute name="valign">top</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
<xsl:element name="table">
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="cellpadding">0</xsl:attribute>
<xsl:attribute name="cellspacing">0</xsl:attribute>
<xsl:text>&#xA;</xsl:text>


<xsl:element name="tr">
<xsl:text>&#xA;</xsl:text>

<xsl:element name="td">
<xsl:attribute name="height">100%</xsl:attribute>
<xsl:attribute name="valign">top</xsl:attribute>
<xsl:attribute name="width"></xsl:attribute>
<xsl:attribute name="style">background-color:#DDD5BD;width:215px</xsl:attribute>
<xsl:text>&#xA;</xsl:text>

<xsl:variable name="ws" select="'http://localhost/abc/WebService.asmx/GetHTML?strURL='"/>

<xsl:variable name="url">
<xsl:choose>
<xsl:when test="$navid='12245'">
<xsl:value-of select="'http://www.yahoo.com'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'http://www.msn.com'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:value-of select="document(concat($ws,$url))"/>

</xsl:element><xsl:text>&#xA;</xsl:text>

<xsl:element name="td">
<xsl:attribute name="height">100%</xsl:attribute>
<xsl:attribute name="style">BACKGROUND-COLOR: #f0f0f0; padding-left: 7px; padding-bottom: 10px; padding-top: 10px;</xsl:attribute>
<xsl:attribute name="valign">top</xsl:attribute>
<xsl:attribute name="width">210</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
<xsl:element name="div">
<xsl:attribute name="id">OBDom</xsl:attribute>
<xsl:attribute name="class">OB</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
</xsl:element>
<xsl:text>&#xA;</xsl:text>
<xsl:element name="div">
<xsl:attribute name="id">OBInt</xsl:attribute>
<xsl:attribute name="class">OB</xsl:attribute>
<xsl:attribute name="style">display: none;</xsl:attribute>
<xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:element><xsl:text>&#xA;</xsl:text>
</xsl:template>
</xsl:stylesheet>

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 18 Apr 2006 10:25 AM
here is my XSL attached.


Documentsample(5).xsl
sample

Postnext
Ivan PedruzziSubject: Calling Web Service Method from XSLT .
Author: Ivan Pedruzzi
Date: 18 Apr 2006 11:15 AM

The posted XSLT is incomplete and contains errors

- It calls a template "link" that is no defined

- Uses a variable $navid that is no defined

- To output the doctype you have to use the following and not xsl:text

<xsl:output method="html" doctype-public='HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN'/>

- The use of xsl:element is inappropriate just use HTML directly
For instance the main template could be re-written so

<xsl:template match="/">
<html>
<head>
<title>My Title</title>
<meta name="keywords" content="xyz"></meta>
<xsl:call-template name="links"/>
</head>
<body>
<xsl:apply-templates select="books/book"/>
</body>
</html>
</xsl:template>

To test the web service open the URL with Stylus Studio XML editor

- File -> Open
http://localhost/abc/WebService.asmx/GetHTML?strURL=www.yahoo.com

- pick the XML editor
- click XML -> Check well-formed



Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 18 Apr 2006 04:32 PM
I have attached my files , Actually XSL file and XML file is valid, I tried to edit some stuff so it got screwd up anyway, file I am attaching is valid XSL, now What's happening when I print the value of <xsl:value-of select="concat($ws,$url)" /> i get the correct value and i can also see good and when I put into the IE , i see the page. but when I use <xsl:value-of select="document(concat($ws,$url))" /> its throwing Transform() error '800a0066' and I am doing translation in ASP. Please let me know what do you think.


Unknownsample(6).xsl

Postnext
Ivan PedruzziSubject: Calling Web Service Method from XSLT .
Author: Ivan Pedruzzi
Date: 18 Apr 2006 04:52 PM

Is there an error message with the number?

Ivan Pedruzzi
Stylus Studio Team

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 18 Apr 2006 05:03 PM
i am only getting following error..

oProc.Transform() error '800a0066'





Postnext
Ivan PedruzziSubject: Calling Web Service Method from XSLT .
Author: Ivan Pedruzzi
Date: 18 Apr 2006 05:40 PM

You should consult the Microsoft API documentation to diagnose the problem


Ivan Pedruzzi
Stylus Studio Team

Postnext
sam desiSubject: Calling Web Service Method from XSLT .
Author: sam desi
Date: 19 Apr 2006 09:23 AM
Is there anyother way , I cam make a call to web service method in outside script and get the result back to XSLT and when I migrate to .NET I can also use that script no need to re-write the script.

THANKS FOR YOUR ALL REPLIES.

Posttop
Brynjar Larssen-AasSubject: Calling Web Service Method from XSLT .
Author: Brynjar Larssen-Aas
Date: 09 Jun 2006 03:55 AM
Looks like you know this stuff Ivan,
so, can you help me with this:
I am working on a project and I am trying to find a way to validate XML-files with XSLT and Webservices. I have made a simple ws that returns a boolean true if the given number is below 50 and false if it is above 50. Now, I want to check this with the use of a variable that contains of the url to the ws (for this test it is something like http://localhost:port/service/check?value=X where X is the number picket up from the XML) I know that the variable containing the url works fine for every value, using a template, but I dont't get the choose or if-test to work.

Basicly I want something like this:
if $variable is true, then print out "value is valid" else "value is not valid"

How is this done?

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.