Pretty basic developer here. I currently use mappath to transform my XSL and XML on the server side. This works famously but only use this BC it was the example used on W3C school site. I am trying to expand some of the capabilities of my page by passing parameters around via the URL string. As you may already know I cannot pass a URL parameter with the mappath method. I cant for the life of me figure out how to do this any other way. Google did not offer and clear examples nor did my wrox book.
Can someone please enlighten me on how to accomplish passing parameters into the XSLT?
I guess I either need to use a new method for serverside transformations or I need to understand a new way to pass parameters.
Thanks all your help in the past has made a huge difference in my project!
KG
My Current Code
<html><title>Report</title>
<head>
</head>
<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("/XML/XMLData/View.xml"))
'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("Data.xsl"))
'Transform file
Response.Write(xml.transformNode(xsl))
%>
</html>
Just to be pedantic for a moment, it is not map path that is doing the transform here. All Server.MapPath does is convert a relative or virtual path (“/XML/XMLData/View.xml” in your case) to a physical directory on the server, which can then be loaded by the XML processor. In your case you are using ASP, so the processor is MSXML.
Fortunately, you this does support the passing of parameters, although you do have to do a little bit of extra work. Try this code sample instead
Within the XSLT itself, you will obviously need to specify the parameter. This is done by using the xsl:param element. This needs to go within the xsl:stylesheet element, near the top, and outside of any xsl:template elements you have
Note that the select attribute in this case specifies a default value should the parameter not be set by the calling code.
I notice you have tagged the question asp.net too, in which case you might want to read up about XSLTCompliled transform, which is the class you use when doing XSLT transformations in .Net.