• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

server variables in XSL

is there any way to access global or server variables in XSL scripting
1 Solution
Hi tommyh,

A sample of how to do it can be found here


On this page the author gives one way how to do it right and a second of how not to do it...

Coming from an excellent overall tutorial here


tommyhAuthor Commented:
is this relevant to asp and msxml parser?, and what about server variables?
You can do this a couple different ways, tommy....

(these all relate specifically to ASP ans msXML, cuz that's what I have experience in)

1) if you have access to IIS, go into the control panel for the server you're working on and register .xml files to be parsed by ASP. This is in "Application properties" or something like that... by default ASP parses only .asp and .inc files. but you can add as many as you like. Then, in you're xml file, you can stick ASP, and everything'll be fine as long as what's returned is valid XML/XSL...

<xsl:template match="//<%=Request.ServerVariables("whatever")%>">

2) if no access to IIS, or its impractical - you can rename your .xml files .asp. Then use the same technique as above. The downside is that these .xml files will no longer work for direct download to an XML-capable client such as IE5 - because it won't see the .xml extension, and therefore won't know to switch to xml mode.

3) the final solution is messy, but sometimes necessary. Instantiate the XMLDom object in ASP, add nodes to the source XML document that represent the global variables you want to get in to XSL, and assign them values. Then your XSL just looks for these added nodes.

Set oXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
Set oXSLDoc = Server.CreateObject("Microsoft.XMLDOM")

oXSLDoc.async = false
oXMLDoc.async = false

set c = oXMLDoc.documentElement
set a = oXMLDoc.createElement("myvar")
set b = oXMLDoc.createTextNode(myvalue)

response.write oXMLDoc.transformNode(oXSLDoc)


  <xsl:value-of select="//myvar"/>


get it??
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now