accessing environment variable in XML

Discussion in 'XML' started by shaun, Sep 22, 2005.

  1. shaun

    shaun Guest

    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.
    shaun, Sep 22, 2005
    #1
    1. Advertising

  2. shaun wrote:

    > 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 22, 2005
    #2
    1. Advertising

  3. shaun

    Peter Flynn Guest

    shaun wrote:

    > 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
    Peter Flynn, Sep 22, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    1
    Views:
    379
    Oscar kind
    Nov 7, 2004
  2. Albretch
    Replies:
    3
    Views:
    5,331
    Albretch
    Nov 8, 2004
  3. Mohanasundaram
    Replies:
    44
    Views:
    1,065
    Keith Thompson
    Aug 24, 2004
  4. Replies:
    5
    Views:
    650
  5. Liquid Technologies
    Replies:
    0
    Views:
    388
    Liquid Technologies
    Oct 23, 2007
Loading...

Share This Page