?
Solved

Can XSLT access the QueryString?

Posted on 2002-03-15
7
Medium Priority
?
1,938 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 150 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

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 count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

770 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