accessing environment variable in XML

S

shaun

Is there anyway to access a system environment variable from within an
xml document?

Two applications:
1) I'd like to make an XBase declared path equal to an environment
variable declared path.
2) In performing an xslt I'd like to insert the username and the OS
architecture in the resulting document.
 
M

Martin Honnen

shaun said:
Is there anyway to access a system environment variable from within an
xml document?

Well an XML document is usually simply a static document and not a
program that can perform tasks like system environment access.

2) In performing an xslt I'd like to insert the username and the OS
architecture in the resulting document.

An XSLT stylesheet can declare global parameters and an XSLT processor
then exposes an API to set those parameters before a transformation is
run. Declaring a parameter is as follows:

<xsl:param name="paramName" select="'intial value if needed'" />

How you set such a parameter before a transformation depends on the
individual XSLT processor's API but that way if you for instance program
in C you would use C to get those values you want, then pass the values
as parameters to the XSLT processor (which in this case would have a C
API) and run the transformation.

The stylesheet can then use e.g.
<xsl:value-of select="$paramName" />
to read out that parameter.
 
P

Peter Flynn

shaun said:
Is there anyway to access a system environment variable from within an
xml document?

Basically, no. XML isn't a programming language, so it doesn't have
access to the environment in which it finds itself being used.

However, there are ways around this, such as having a cron script
maintain a separate file with the current date and the value of
certain variables in XML markup, updated at specified intervals,
and have this file included in the XML document using the normal
file entity mechanism. Not robust, but functional for many purposes.
Two applications:
1) I'd like to make an XBase declared path equal to an environment
variable declared path.
2) In performing an xslt I'd like to insert the username and the OS
architecture in the resulting document.

You could use that method to do both of them. Just remember that if
you move the application to another location/machine/OS/environment
it will break unless you also maintain the external data source.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top