Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help to send querystring to XSLT

Posted on 2008-01-29
14
Medium Priority
?
3,972 Views
Last Modified: 2013-11-18
Hello,

"the_crazed" helped me setup some code to allow me to drag information from a web site using SOAP, classic ASP and XSLT. One problem I have is that I need to send a catalog ID to the XSLT so I can dynamically create a URL with this querystring.

An example of a catlod ID to send is as follows:

http://www.rugbyshop.co.nz/products.asp?catid=103

I need to pass "103" to the XSLT. I have read about using IXSLProcessor but I just can't seem to implement it in my code. Can someone help?
This is my code in the products.asp file:
 
<%
Dim objXMLHTTP : SET  objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
Dim objOutputXMLDoc : Set objOutputXMLDoc = Server.CreateObject("MSXML.DOMDocument")
 
Dim strMethodPkg
Dim strMethodResultXML
 
Dim catID		:	catID = request("catID")
Dim Html_Strip	: Html_Strip = 1
 
 
strMethodPkg ="<?xml version=""1.0"" encoding=""utf-8""?>"
strMethodPkg = strMethodPkg &"<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/"">"
strMethodPkg = strMethodPkg & "<soap:Body>"
strMethodPkg = strMethodPkg & "<Product_List_Xml xmlns=""http://www.estaronline.com/webservices/"">"
strMethodPkg = strMethodPkg & "<catID>" & catID &"</catID>"
strMethodPkg = strMethodPkg & "<Html_Strip>1</Html_Strip>"
strMethodPkg = strMethodPkg & "</Product_List_Xml></soap:Body></soap:Envelope>"
 
objXMLHTTP.open "post", "http://www.champions.co.nz/shop/products2.asmx", False
 
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strMethodPkg)
 
objXMLHTTP.setRequestHeader "SOAPAction", "http://www.estaronline.com/webservices/Product_List_Xml"
 
Call objXMLHTTP.send(strMethodPkg)
 
strMethodResultXML = objXMLHTTP.responseText
 
objOutputXMLDoc.LoadXml(strMethodResultXML)
 
sXml = objOutputXMLDoc.SelectSingleNode("//Product_List_XmlResult").ChildNodes(0).xml
 
Set objXml = Server.CreateObject("Microsoft.XmlDom")
Set objXsl = Server.CreateObject("Microsoft.XmlDom")
 
objXml.LoadXml(sXml)
objXsl.Load(Server.MapPath("product.xslt"))
sProduct = objXml.transformNode(objXsl)
 
%>
 
 
Here is the product.xslt file. I tried using "<xsl:value-of select="//Quersystring/@catID"/>" but it didn't work
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
 
    <xsl:apply-templates select="iSAMS/PRODUCTS/product"/>
</xsl:template>
 
<xsl:template match="product">
<tr>
    <td width="140" valign="top"><div align="center">
	<a><xsl:attribute name="target">_blank</xsl:attribute><xsl:attribute name="href">http://www.champions.co.nz/shop/affiliate.asp?afid=8&amp;c=<xsl:value-of select="//Quersystring/@catID"/>&amp;p=<xsl:value-of select="@pdID"/></xsl:attribute>
	<img border='0'><xsl:attribute name="src">http://www.champions.co.nz/shop/productimages/<xsl:value-of select="@ImageSmall"/></xsl:attribute></img>
			</a></div></td>
 
      
    
    <td valign="top">
	<a><xsl:attribute name="target">_blank</xsl:attribute><xsl:attribute name="class">shop-products-big</xsl:attribute><xsl:attribute name="href">http://www.champions.co.nz/shop/affiliate.asp?afid=8&amp;c=<xsl:value-of select="//Querystring/@catID"/>&amp;p=<xsl:value-of select="@pdID"/></xsl:attribute><xsl:value-of select="@Product"/></a><br/><br/><xsl:value-of select="@LongDescription" disable-output-escaping="yes"/>
<br/><br/><img><xsl:attribute name="src">../images/arrowspace.gif</xsl:attribute><xsl:attribute name="width">14</xsl:attribute><xsl:attribute name="height">8</xsl:attribute></img><a><xsl:attribute name="target">_blank</xsl:attribute><xsl:attribute name="class">body-bold-red</xsl:attribute><xsl:attribute name="href">http://www.champions.co.nz/shop/affiliate.asp?afid=8&amp;c=<xsl:value-of select="//Quersystring/@catID"/>&amp;p=<xsl:value-of select="@pdID"/></xsl:attribute>More Information...</a><br/><br/><br/><br/></td>
  </tr>
  </xsl:template>
</xsl:stylesheet>

Open in new window

0
Comment
Question by:Pete_Zed
  • 8
  • 6
14 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20775291
I recommend that you don't go changing the XSLT object with DOM methods,
but that you pass a parameter in... ever so easy

you need a template processor for that
and you should not use the old style xml objects, but at least a version 2 of msxml
I have msxml4 installed and I refer to that one, you could (even better) install msxml6 and refer to that,
or stick to msxml3 as you are using now, but in version2 mode by making the 4.0 into 6.0 or 3.0 as you please

Set oXML = Server.CreateObject("MSXML2.DOMDocument.4.0")
Set oXSL= Server.CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
Set oTmpl= Server.CreateObject("Msxml2.XSLTemplate.4.0")

oXSL.async = false
oXSL.load Server.MapPath("product.xslt")
oXML.load Server.MapPath(sXml)

oTmpl.stylesheet = oXSL

Set oProc= oTmpl.createProcessor()
oProc.input = oXML
 
oProc.addParameter "catID", catID
oProc.output = Response
oProc.transform()

now you need a parameter catID in your XSLT
<xsl:param name="catID"/>
at the highest level in your stylesheet

and then you can use that as $catID in your stylesheet

cheers

Geert
0
 
LVL 8

Author Comment

by:Pete_Zed
ID: 20779848
When I insert this code into my exisiting code, I receive this error message:

Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/products.asp, line 43
800401f3

Line 43 is Set oXML = Server.CreateObject("MSXML2.DOMDocument.4.0"). When I tried changing DOMDocument.4.0 to 3.0, I receive this:

Server.MapPath() error 'ASP 0214 : 80004005'
Invalid Path parameter
/products.asp, line 49
The Path parameter excedes the maximum length allowed.

Line 49 is oXML.load Server.MapPath(sXml).

I have place the code you supplied after sXml = objOutputXMLDoc.SelectSingleNode("//Product_List_XmlResult").ChildNodes(0).xml and before Set objXml = Server.CreateObject("Microsoft.XmlDom") from my original code. Is this correct?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 450 total points
ID: 20780928
> Server.CreateObject Failed
because you don't have msxml4 installed

> The Path parameter excedes the maximum length allowed
Because I had a bug in my code (server.mappath with the sXML), I needed to drop the server.mappath in that line

About locating the code, it is more or less a merge
(note that I consistently use msxml6 in the entire code, I do recommend that you install msxml6 on your server)

<%
Dim objXMLHTTP : SET  objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.6.0")
Dim objOutputXMLDoc : Set objOutputXMLDoc = Server.CreateObject("MSXML.DOMDocument")
 
Dim strMethodPkg
Dim strMethodResultXML
 
Dim catID            :      catID = request("catID")
Dim Html_Strip      : Html_Strip = 1
 
 
strMethodPkg ="<?xml version=""1.0"" encoding=""utf-8""?>"
strMethodPkg = strMethodPkg &"<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/"">"
strMethodPkg = strMethodPkg & "<soap:Body>"
strMethodPkg = strMethodPkg & "<Product_List_Xml xmlns=""http://www.estaronline.com/webservices/"">"
strMethodPkg = strMethodPkg & "<catID>" & catID &"</catID>"
strMethodPkg = strMethodPkg & "<Html_Strip>1</Html_Strip>"
strMethodPkg = strMethodPkg & "</Product_List_Xml></soap:Body></soap:Envelope>"
 
objXMLHTTP.open "post", "http://www.champions.co.nz/shop/products2.asmx", False
 
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strMethodPkg)
 
objXMLHTTP.setRequestHeader "SOAPAction", "http://www.estaronline.com/webservices/Product_List_Xml"
 
Call objXMLHTTP.send(strMethodPkg)
 
strMethodResultXML = objXMLHTTP.responseText
 
objOutputXMLDoc.LoadXml(strMethodResultXML)
 
sXml = objOutputXMLDoc.SelectSingleNode("//Product_List_XmlResult").ChildNodes(0).xml

Dim oXML
Set oXML = Server.CreateObject("MSXML2.DOMDocument.6.0")
Dim oXSL
Set oXSL= Server.CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
Dim oTmpl
Set oTmpl= Server.CreateObject("Msxml2.XSLTemplate.6.0")
Dim oProc

oXSL.async = false
oXSL.load Server.MapPath("product.xslt")
oXML.load(sXml)

oTmpl.stylesheet = oXSL

Set oProc= oTmpl.createProcessor()
oProc.input = oXML
 
oProc.addParameter "catID", catID
oProc.output = Response
oProc.transform()
 
%>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:Pete_Zed
ID: 20782175
I will endevour to see if my web host provider will upgrade to MSXML6. If not, what are the options?
0
 
LVL 8

Author Comment

by:Pete_Zed
ID: 20783557
I tried to load msxml6 on a server but it stated that it already had a higher version.

When I ran the code all that appeared was a line at the top of the page -

??xml version="1.0" encoding="UTF-16"?>

and then the rest of the page loaded but it did not bring back any data.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20784337
> If not, what are the options
stick to msxml3 and use 3.0 instead of 6.0 allover
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20784343
I assume you are now into some debugging.

Try to show some messages step by step to see where it goes wrong... I can't do that from a distance
0
 
LVL 8

Author Comment

by:Pete_Zed
ID: 20789612
It seems to be somewhere in this section:

Dim oXML
Set oXML = Server.CreateObject("MSXML2.DOMDocument.6.0")
Dim oXSL
Set oXSL= Server.CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
Dim oTmpl
Set oTmpl= Server.CreateObject("Msxml2.XSLTemplate.6.0")
Dim oProc

oXSL.async = false
oXSL.load Server.MapPath("product.xslt")
oXML.load(sXml)

oTmpl.stylesheet = oXSL

Set oProc= oTmpl.createProcessor()
oProc.input = oXML
 
oProc.addParameter "catID", catID
oProc.output = Response
oProc.transform()

As I can display the value of sXml the line before this code and all looks good. But once it hits here it seems to screw around a bit to display the ??xml version="1.0" encoding="UTF-16"?> at the top left corner of the page.
0
 
LVL 8

Author Comment

by:Pete_Zed
ID: 20789760
Further to that, in the source code of the asp page is this: ÿþ< ? x m l   v e r s i o n = " 1 . 0 "   e n c o d i n g = " U T F - 1 6 " ? > and nothing else. It seems odd that there are spaces between each character too.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20789879
> It seems odd that there are spaces between each character too

No, it isn't strange. UTF-16 uses two bytes per character. If you would look at it i a UTF-16 aware editor, you would not notice the spaces.
If you look at it in a text-editor that is UTF-16 unaware, you would see an extra space between each character

I need to think on how to best devbug your full page

cheers

Geert
0
 
LVL 8

Author Comment

by:Pete_Zed
ID: 20805580
I changed this line:

oXSL.load Server.MapPath("ab.xslt")
oXML.Load(sXml)

to this line:

oXSL.load(Server.MapPath("ab.xslt"))
oXML.LoadXml(sXml)

and now the "catID" querystring is passed to the XSLT. But I am still getting the "ÿþ" symbols at the top of the page.
0
 
LVL 8

Author Comment

by:Pete_Zed
ID: 20805599
I have found a solution to this by adding this line to the XSLT file:

<xsl:output encoding="utf-8"/>

After that it was encoded as UTF-8 and the strange symbol has disappeared.
0
 
LVL 8

Author Closing Comment

by:Pete_Zed
ID: 31426247
Thanks for your help. I may need help with filters and page numbering/breaks shortly.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20810617
correct
"ÿþ"
is the Byte Order Mark
and is only used with UTF-16
I didn't pay much attention to this over the weekend
I am happy you sorted it out
cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question