Solved

Using environment variable from within XSLT

Posted on 2002-05-21
5
2,360 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to silent print from safari browser 6 138
XML to SQL Table using c# 5 47
c# code 19 61
Import data into excel from web page 10 28
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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, …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

744 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

10 Experts available now in Live!

Get 1:1 Help Now