Solved

Can XSLT access the QueryString?

Posted on 2002-03-15
7
1,934 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML Data Missing in PHP SimpleXML 8 83
Get the parent node - XMLTYPE 9 114
AL3 Files 4 48
PHP delete contents of file- before writing to it 6 49
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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