• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4017
  • Last Modified:

Help to send querystring to XSLT

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
Pete_Zed
Asked:
Pete_Zed
  • 8
  • 6
1 Solution
 
Geert BormansInformation ArchitectCommented:
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
 
Pete_ZedAuthor Commented:
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
 
Geert BormansInformation ArchitectCommented:
> 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Pete_ZedAuthor Commented:
I will endevour to see if my web host provider will upgrade to MSXML6. If not, what are the options?
0
 
Pete_ZedAuthor Commented:
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
 
Geert BormansInformation ArchitectCommented:
> If not, what are the options
stick to msxml3 and use 3.0 instead of 6.0 allover
0
 
Geert BormansInformation ArchitectCommented:
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
 
Pete_ZedAuthor Commented:
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
 
Pete_ZedAuthor Commented:
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
 
Geert BormansInformation ArchitectCommented:
> 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
 
Pete_ZedAuthor Commented:
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
 
Pete_ZedAuthor Commented:
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
 
Pete_ZedAuthor Commented:
Thanks for your help. I may need help with filters and page numbering/breaks shortly.
0
 
Geert BormansInformation ArchitectCommented:
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.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now