Re: [xsl] Batch processing

Subject: Re: [xsl] Batch processing
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 29 May 2007 10:39:23 +0200
There's no such thing as a for-each loop in XSLT (at least not that compares to a C++ style for-loop). The closest what you can have is xsl:for-each, but it does not "loop", instead you tell the processor to execute the sequence constructor for all nodes in the node set, in any order (but note that this does not influence the output order), in parallel or not.

In Perl you can do a lot that you cannot (easily) do in XSLT and in XSLT you can do a lot that you cannot (easily) do in Perl. Choose the language that suits the job wisely.

If you want to call something from the commandline, you will have to write an extension function or instruction. But I consider it highly unlikely that it is needed to call a commandline from XSLT. If it is needed to call another program with certain parameters, choose a workflow system, or if you must it is better to use URIs and use the document function and act upon the return XML (you *must* return XML), which will make your XSLT "interactive" with the environment.

Finally, what MK suggested exactly resembles a way you can also use in a xsl:for-each instruction or any instruction for that matter. xsl:for-each is in essence the same as xsl:apply-templates + matching template (but the difference is in the method, first method is: you choose what must be done, second method is: you let the programmer choose). Which method suits best depends on your data and your personal taste. It has nothing to do with whether you call a commandline or not (as a matter of fact, everything concerning nodes that you can express in a for-each you can also express in an apply-templates).

Did you already try: <xsl:for-each select="document(xmlFile)">....?

Cheers,
-- Abel Braaksma


J. S. Rawat wrote:
...but I want it to call it within for-each loop and want to call commandline. If you are aware of Perl, we can do it by $sh.

At 01:03 PM 5/28/2007 +0100, you wrote:
You don't need the collection() function for this, you can do it with
document(). With <dir> as your current node, do

<xsl:apply-templates select="document(xmlFile)" mode="m"/>

and it will cause each of these input documents to be processed.

Michael Kay
http://www.saxonica.com/

Current Thread