Solved

Can XSLT access the QueryString?

Posted on 2002-03-15
7
1,932 Views
Last Modified: 2013-11-18
I need to build a link on my page based on QueryString values.  How if at all can I access the QuerySting using in an XSLT?
0
Comment
Question by:whitej8
  • 4
  • 2
7 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 50 total points
ID: 6870586
Hi whitej8, you can use the addparameter as in this sample
http://www.dpawson.co.uk/xsl/sect4/N9503.html#d285e51
look for the last snippet on the page how to pass a param from asp to the xslt tranformation

HTH:O)Bruintje
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6870711
if as i presume you are using something like
data.xml?param1=1, i.e. you are using the <?xml-stylesheet..?> pi, and you are using MSXML3/4, the answer is YES.

However this is a very bad design decision, you should be passing external values to the stylesheet via the IXSLProcessor's addParameter method. Which means that instead of using the xml-stylesheet pi, you shd be using scripted transformation.
0
 

Author Comment

by:whitej8
ID: 6876966
I am not using MSXML.  I am using Perl to instanciate an instance of Sablotron to transform my XML.  I need to build a new link passing parameters from the QueryString.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 23

Expert Comment

by:b1xml2
ID: 6877027
you could use the DOM to reference the xsl:param in the XSLT document and append the value as a TextNode
0
 

Author Comment

by:whitej8
ID: 6877094
Can you explain this a little more?
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6877309
i am exposed to MSXML only although I have SAXON on my box, so you would have to translate the code to perl.

Sample XSLT Document
====================
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" version="1.0" encoding="iso-8859-1" />
<xsl:param name="external" />
<xsl:template match="/">
<!--example-->
<div><xsl:value-of select="$external" /></div>
</xsl:template>
</xsl:stylesheet>

Code (ASP/JScript)
==============
<%
 //INSTANTIATING COM OBJECTS
 var oXML = Server.CreateObject("Msxml2.DOMDocument.4.0");
 var oXSLT = Server.CreateObject("Msxml2.DOMDocument.4.0");
 //SYNCHRONOUS LOADING
 oXML.async = oXSLT.async = false;
 //LOADING MAIN XML DOCUMENT
 oXML.load(Server.MapPath("xml/data.xml"));
 //LOADING XSLT DOCUMENT
 oXSLT.load(Server.MapPath("xslt/data.xsl"));
 //GETTING QUERYSTRING VALUES
 var szExternal = Request.QueryString("data");
 //GETTING REFERENCE TO ELEMENT IN XSLT DOCUMENT
 //W3C METHOD FOLLOWED AS CLOSELY AS POSSIBLE
 //MS HAS EASIER EXTENSIONS
 var oNodeList = oXSLT.getElementsByTagName("param");
 var oAttrib;
 var oNode;
 for (var i=0;i<oNodeList.length;i++) {
  //find name attribute value
  oNode = oNodeList.item(i);
  //NON-W3C
  oAttrib = oNode.attributes.getNamedItem("name");
  if (oAttrib.nodeValue == "external") {
   //FOUND TARGET PARAMETER TO PASS EXTERNAL VALUE
   //CREATE TEXT NODE AND APPEND TO NODE
   oNode.appendChild(oXSLT.createTextNode(szExternal));
   //STOP LOOPING
   break;
  }  
 }
 //PERFORM TRANSFORMATION
 oXML.transformNodeToObject oXSLT, Response
%>

0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6877316
typo
====
var oNodeList = oXSLT.getElementsByTagName("xsl:param");
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

774 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