Solved

Using environment variable from within XSLT

Posted on 2002-05-21
5
2,485 Views
Last Modified: 2013-11-18
Hi,
I am new to XSLT.
Is it possible to use the value of a system environment variable (e.g. TEMP), from within XSLT?
0
Comment
Question by:mco
[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
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 7025860
Since you are so new to XSLT, you must understand that XSLT is not a panacea for every coding dilemma. It was designed to carry out transforms on XML Documents which are nothing more than structured TEXT. For optimal performance and yes! there are situations where you can cause a stack overflow or crash your XSLT Engine for any parser.

One of the things that you will learn is NOT to re-invent the wheel. There are existing API calls that allow you to get system environment variables like Windows Scripting Host. XSLT is NOT a scripting language. It is not a procedural language.

::TIP::
1. Get the System Environment Variable.
2. Pass It To The Stylesheet
2a. External Values can be passed to Stylesheets either thru brute DOM Methods or via the AddParameter() Method of the IXSLProcessor (if you are using MSXML 3+)
0
 
LVL 1

Author Comment

by:mco
ID: 7026161
Could you give me a code example?
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7026266
In which language? C#, VB, JScript, VBScript

On Which Side? Client Or Server?

Using What Technology? HTA, ASP, ASP.NET, COM (ActiveX)

0
 
LVL 1

Author Comment

by:mco
ID: 7026617
C++, client, COM (msxml3.dll)
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 100 total points
ID: 7027330
I didnt offer C++ as I have no working knowledge of that.

The following example requires:
1. Windows Scripting Host
2. MSIE 5+
3. MSXML3.

xml/data.xml
=============
<?xml version="1.0"?>
<files>
<file name="Windows Installer 3.0" href="msinstaller.exe" />
</files>


xslt/data.xsl
=============
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" indent="yes" />
<xsl:param name="temp-folder" />
<xsl:template match="/">
<xsl:for-each select="//file">
<div><a href="{$temp-folder}\{@href}"><xsl:value-of select="@name" /></a></div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


data.hta
=========
<html>
<head>
<title>IXSLProcessor::MSXML3</title>
<script language="javascript">
var oShell = new ActiveXObject("WScript.Shell");
var oEnv = oShell.Environment("PROCESS");
var szTemp = oEnv("TEMP");
//clear WScript Objects
delete oEnv; oEnv = null; CollectGarbage();
delete oShell; oShell = null; CollectGarbage();
//create XSLTemplate30
var oTemplate = new ActiveXObject("Msxml2.XSLTemplate.3.0");
//create DOMDocument30
var oXML = new ActiveXObject("Msxml2.DOMDocument.3.0");
//create FreeThreadedDOMDocument30
var oXSLT = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
oXSLT.async = oXML.async = false;
//loading XSLT Document
oXSLT.load("xslt/data.xsl");
//setting stylesheet property to the XSLT Tree
oTemplate.stylesheet = oXSLT;
//clear XSLT reference - no longer needed
delete oXSLT; oXSLT = null; CollectGarbage();
oXML.load("xml/data.xml");
//create IXSLProcessor
var oProc = oTemplate.createProcessor();
//set the input property to the XML Tree
oProc.input = oXML;
//passing external values to a named parameter
oProc.addParameter("temp-folder",szTemp);
window.onload = init;
function init() {
  //perform transformation
  oProc.transform();
  document.body.innerHTML = oProc.output;

}
</script>
</head>
<body></body>
</html>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

705 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