Re: Calling a function using a variable name

Martin Klang <[email protected]> Sat, 5 Feb 2005 22:25:17 +0000
Newsgroups gmane.text.xml.o-xml
Message-ID <[email protected]>
There's of course another possiblity which I didn't think of -
you can use XSLT or o:XML to generate a program, or a Factory type.

However in your case you want to load and invoke a set of modules based 
on an XML configuration file, right?
With the new Program type in 1.1.0 it's very easy to run and include 
results from one program in another.

Say the config file contains lines like these:
     <module name="blog" file="modules/blog.oml"/>
     <module name="foo" file="modules/foo.oml"/> ...etc
Say then that each module is an o:XML program that takes a predefined 
set of parameters, and produces some output.
You could then iterate over the config lines, load the corresponding 
module, set any parameters and run the program ->

<o:set cfg="io:File('config.xml').parse()"/> <!-- load config file -->
<o:for-each select="$cfg//module"> <!-- iterate over module elements -->
   <o:set module="Program(@file)"/> <!-- load program -->
   <o:do select="$module.setParameter('input', $input)"/> <!-- set a 
program parameter, called 'input' -->
   <o:eval select="$module.run()"/> <!-- compile and run the program, 
return the output -->
</o:for-each>

would that work for you?

/m