Solved

Can XSLT access the QueryString?

Posted on 2002-03-15
7
1,935 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 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

737 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