Solved

Can XSLT access the QueryString?

Posted on 2002-03-15
7
1,928 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
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
Comment Utility
Can you explain this a little more?
0
 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
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
Comment Utility
typo
====
var oNodeList = oXSLT.getElementsByTagName("xsl:param");
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now