Jump to content

Asp And Xmldom Passing Url Parameters


mstransky
 Share

Recommended Posts

This is not a question, this is a fix that I came across. Many people out on the web which use jscript xmldom to have an xml output in xslt.I will make a tutorial example later and send it to w3schools if they like to use as a side by side comparison to show if work.xml sample-----------<aspxml> <admin> <username>your login in if needed</username> <password>your pass word if needed</password> </admin> <RECORDS> <ITEM><ID>0</ID><AA>Y</AA><BB>b</BB><CC>Equine</CC><DD>that company name Inc.</DD><EE>www.someurl.com</EE><FF>../image location/../486x60.jpg</FF><GG>here is a write up descriptiton of the sites products.</GG><HH>60</HH><II>486</II><JJ></JJ><KK></KK><LL></LL><MM></MM><NN></NN><OO></OO><PP></PP><QQ></QQ><RR></RR><SS></SS><TT></TT><UU></UU><VV></VV><WW></WW><XX></XX><YY></YY><ZZ></ZZ></ITEM> <ITEM>...more records.....<ITEM></RECORDS></aspxml>-------------------end---------------here is the asp code in jscript-----------------------<%@ Language=JScript%> <%Server.ScriptTimeout=21478836%> <%Response.Buffer=false%><%var request = (Request.QueryString("q"));%><%var objXMLDoc = Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");objXMLDoc.async = false;objXMLDoc.load(Server.MapPath("../../l-links.xml"));//a) Build the XPath Queryvar xmlQuery = "//RECORDS/ITEM[CC = '"+ request +"']";//:) Create a nodeset for the selected XPathvar objNodes = objXMLDoc.selectNodes(xmlQuery);//c) Create an instance of the xslt objectvar xsl=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");xsl.async = false;xsl.load(Server.MapPath("../../l-links.xsl"));//d) Create an instance of the template object to add the parametervar xslt = Server.CreateObject("Msxml2.XSLTemplate");xslt.stylesheet = xsl;xslProc = xslt.createProcessor();xslProc.input = objXMLDoc;xslProc.addParameter("sortBy", "DD"); //Passing in the Sort CriteriaxslProc.addParameter("strXPath", objNodes); //Passing in a Nodeset as a second parameter//e) Apply the Transformation and write the results as outputxslProc.transform();var sortedData=xslProc.output;Response.Write(sortedData)%>----------------end-----------------------here is the code for vbscript-------------------------------------------<%Dim sortitby, sortBy, filterfor, filterByif Request.querystring("q") <> "" thenfilterfor = Request.querystring("q")else filterfor = " "end ifSortitBy = "DD"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title><%=filterfor%></title></head><body><%set objXMLDoc = Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM")objXMLDoc.async = falseobjXMLDoc.load(Server.MapPath("../../l-links.xml"))//a) Build the XPath Query// not needed like in jsscript//:) Create a nodeset for the selected XPath// not neededlike in jscript//c) Create an instance of the xslt objectset xsl=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM")xsl.async = falsexsl.load(Server.MapPath("../../l-linkscopy.xsl"))//d) Create an instance of the template object to add the parameterset xslt = Server.CreateObject("Msxml2.XSLTemplate")xslt.stylesheet = xslset xslProc = xslt.createProcessor()xslProc.input = objXMLDocxslProc.addParameter "sortBy", sortitby //Passing in the Sort CriteriaxslProc.addParameter "filterBy", filterfor //Passing in the filter Criteria//e) Apply the Transformation and write the results as outputxslProc.input = objXMLDocxslProc.transform()Response.Write(xslProc.output)%></body></html>-----------------------------------compare the xsl files for jscript in asp--------------------------<?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- Note that I have specified the default values for the parameters. If no values are passed in, these will be used --> <xsl:param name="sortBy" select="*"/> <xsl:param name="strXPath" select="//ITEM"/> <xsl:template match="/"> <xsl:apply-templates select="$strXPath"> <xsl:sort select="*[name()=$sortBy]" order="ascending"/> </xsl:apply-templates> </xsl:template> <xsl:template match="ITEM"> <xsl:choose> <xsl:when test="AA = 'Y' and BB = 't'"> <p><xsl:element name="a"> <xsl:attribute name="href">http://<xsl:value-of select="EE"/></xsl:attribute> <xsl:value-of select="DD"/></xsl:element><br/><xsl:value-of select="GG"/> </p> </xsl:when> <xsl:when test="AA = 'Y' and BB = 'b'"> <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="EE"/></xsl:attribute> </xsl:element> <p><xsl:element name="a"> <xsl:attribute name="href">http://<xsl:value-of select="EE"/></xsl:attribute> <xsl:value-of select="DD"/> <br/> <span class="img"><img src="http://{FF}" width="{II}" height="{HH}" border="0"/></span> </xsl:element> </p> </xsl:when> <xsl:when test="AA = 'Y' and BB = 'a'"> <p><xsl:element name="a"> <xsl:attribute name="href">http://<xsl:value-of select="EE"/></xsl:attribute> <xsl:value-of select="DD"/> <br/> <span class="img"><img src="http://{FF}" width="486px" height="60px" border="0"/></span> </xsl:element><br/><xsl:value-of select="GG"/> </p> </xsl:when> <xsl:when test="AA = 'N'"> <small><xsl:text>- </xsl:text><xsl:value-of select="DD"/><xsl:text> </xsl:text>...coming</small> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </xsl:template></xsl:stylesheet>------------------------end-------------------------here is the fix for vbscript xsl where to modify----------------------------------------------<?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- Note that I have specified the default values for the parameters. If no values are passed in, these will be used --> <xsl:param name="sortBy" select="*"/> <xsl:param name="filterBy" select="*"/> <xsl:param name="strXPath" select="//ITEM"/> <xsl:template match="/"> <xsl:apply-templates select="$strXPath"> <xsl:sort select="*[name()=$sortBy]" order="ascending"/> </xsl:apply-templates> </xsl:template> <xsl:template match="ITEM"> <xsl:choose> <xsl:when test="AA = 'Y' and BB = 't' and CC = $filterBy"> <p><xsl:element name="a"> <xsl:attribute name="href">http://<xsl:value-of select="EE"/></xsl:attribute> <xsl:value-of select="DD"/></xsl:element><br/><xsl:value-of select="GG"/> </p> </xsl:when> <xsl:when test="AA = 'Y' and BB = 'b' and CC = $filterBy"> <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="EE"/></xsl:attribute> </xsl:element> <p><xsl:element name="a"> <xsl:attribute name="href">http://<xsl:value-of select="EE"/></xsl:attribute> <xsl:value-of select="DD"/> <br/> <span class="img"><img src="http://{FF}" width="{II}" height="{HH}" border="0"/></span> </xsl:element> </p> </xsl:when> <xsl:when test="AA = 'Y' and BB = 'a' and CC = $filterBy"> <p><xsl:element name="a"> <xsl:attribute name="href">http://<xsl:value-of select="EE"/></xsl:attribute> <xsl:value-of select="DD"/> <br/> <span class="img"><img src="http://{FF}" width="486px" height="60px" border="0"/></span> </xsl:element><br/><xsl:value-of select="GG"/> </p> </xsl:when> <xsl:when test="AA = 'N'"> <small><xsl:text>- </xsl:text><xsl:value-of select="DD"/><xsl:text> </xsl:text>...coming</small> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </xsl:template></xsl:stylesheet>----------------------------------------------the small differences that i found are the vbscript in the asp page is grabbing the q string and making a parameter out of itthat parameter is then passed to the xslthe xsl needs this line code add to it as<xsl:param name="filterBy" select="*"/>this way the value can be use as a coimparrision check like this during a when test=<xsl:when test="AA = 'Y' and BB = 'a' and CC = $filterBy">both these scripts work just find, the only problem I found is when the query string is missing injscript the parse just passes a blank value.However with the vbscript when there is no q string value passed the xslt errors out so I added this vbscript line of code as a work around--------if Request.querystring("q") <> "" thenfilterfor = Request.querystring("q")else filterfor = " "end if-----------this way a vaule will not be missing, if the url does not contain a vaule,at least it will be " " and not outright missing.--------------------------------------------------------------------------------------I hope this helps those who have stuggled with those other sites asking that question but have never seen an true answer posted or even a working example.PS I am sure some code can be added to the vbscript example for buffer overruns or what not like the jscript has like so<%@ Language=JScript%> <%Server.ScriptTimeout=21478836%> <%Response.Buffer=false%>any way I hope that helps at least one person, if you ever wanted to persue that kind of coding!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...