RE: [xsl] Variable assignment outside XSL

Subject: RE: [xsl] Variable assignment outside XSL
From: "Roger Glover" <glover_roger@xxxxxxxxx>
Date: Mon, 3 Feb 2003 12:06:04 -0600
Delaney Robin wrote:
> Is it possible to assign variables outside of XSL which can be accessed
> within (during transformation).

Not using system variables, like in a shell script or .bat file.

... skipping to the bottom ...
> Or is there
> any suggested method to pass info into XSL ?

Yes, you are looking for parameter semantics (<xsl:param>), but the usage is

... skipping back to where we were ...
> I need to create extra elements in an XML
> file  to hold values like date-time, username, filename(can I get this
> document()?), servername etc...........

Use this syntax inside the XSLT source:

    <xsl:transform ....>
        <xsl:param name="date-time"/>
        <xsl:param name="username"/>
        <xsl:param name="filename"/>
        <xsl:param name="servername"/>

        .... rest of transform goes here ....


Outside the transform syntax for passing in parameters varies according to
vendor and execution context.  For example, in Xalan-J, using the java
executable class "Process", you would write a command line something like
this (pardon the long line overflow):

    java org.apache.xalan.xslt.Process -IN file.xml -XSL trans.xsl -PARAM
date-time "2003-02-03T11:35" -PARAM username roger -PARAM filename
file.xml -PARAM servername hikimi

On the other hand, if you were running the transformation from within a java
program, adding the parameters would look something like this:

    javax.xml.transform.Transformer transformer;

    ... other code to instantiate and configure "transformer" omitted ...

    transformer.setParameter("date-time", "2003-02-03T11:35");
    transformer.setParameter("username", "roger");
    transformer.setParameter("filename", "file.xml");
    transformer.setParameter("servername", "hikimi");

I hope this helps!

-- Roger Glover

 XSL-List info and archive:

Current Thread