accessing environment variable in XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shaun

    #1

    accessing environment variable in XML

    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.
  • Martin Honnen

    #2
    Re: accessing environment variable in XML



    shaun wrote:
    [color=blue]
    > Is there anyway to access a system environment variable from within an
    > xml document?[/color]

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

    [color=blue]
    > 2) In performing an xslt I'd like to insert the username and the OS
    > architecture in the resulting document.[/color]

    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="$paramN ame" />
    to read out that parameter.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Peter Flynn

      #3
      Re: accessing environment variable in XML

      shaun wrote:
      [color=blue]
      > Is there anyway to access a system environment variable from within an
      > xml document?[/color]

      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.
      [color=blue]
      > 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.[/color]

      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

      Comment

      Working...