[oXygen-user] Batch transformations

George Cristian Bina
Tue Oct 27 05:58:34 CDT 2009


Dear John,

When you configure a transformation scenario to transform XML with XSLT 
you can choose indeed one XML file and one XSLT file. However, you can 
use editor variables to specify the XML file, for example if you specify 
the XML file as

${currentFileURL}

(which is what oXygen sets as default) then this will be expanded at 
runtime to whatever the current file is and you will be able to reuse a 
scenario for other files.

 From the project view you can associate a scenario on a folder or on 
multiple files and you can also trigger the transformations on a folder 
or on multiple files. When you select a folder and use the "Apply 
Transformation Scenario" action then all the files from that folder will 
be iterated, each becoming the current file at its turn and the scenario 
associated with each file will be executed.

So, in order to apply a stylesheet on the files from a folder all you 
need is a scenario that specifies as XML URL ${currentFileURL} and then 
associate it on the folder from the project view and trigger the batch 
transformation also from the project view with the Apply Transformation 
Scenario" contextual action.

In version 11 we added also XProc support. You should be able to create 
and execute from oXygen an XProc pipeline that can iterate over the 
files in a folder and apply an XSLT transformation on each. Here it is 
an example. It assumes you have a structure like

test.xpl
xml/
   test1.xml
   test2.xml
   etc.
xsl/
   test.xsl
results/

The pipeline test.xpl will apply the xsl/test.xsl stylesheet on each of 
the files from the xml folder and the results will be placed in the 
results folder, with files having the same names as the XML input documents.
Here it is the test.xpl pipeline:

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" 
xmlns:c="http://www.w3.org/ns/xproc-step">
   <p:directory-list path="xml"/>
   <p:filter select="//c:file"/>
   <p:for-each name="iterate">
     <p:load>
       <p:with-option name="href" select="concat('xml/', /*/@name)"/>
     </p:load>
     <p:xslt>
       <p:input port="parameters"><p:empty/></p:input>
       <p:input port="stylesheet">
         <p:document href="xsl/test.xsl"/>
       </p:input>
     </p:xslt>
     <p:store>
       <p:with-option name="href" select="concat('results/', /*/@name)">
         <p:pipe port="current" step="iterate"/>
       </p:with-option>
     </p:store>
   </p:for-each>
</p:declare-step>

Best Regards,
George
-- 
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

John Fitzpatrick wrote:
> Batch transformations is something I've been trying to do for a while. I
> have one XSL and I was to run it against ~50 XML files.  Currently I
> have to run something like this in a dos shell: 
> 
> java  -jar saxon9.jar -s:. -xsl:transform.xsl
> 
> Under "Configure transformation scenario..." it allows you to select one
> XSL and one XML. It would be nice if you could select a directory for
> the XML (so run against all XML in that directory), or specify *.xml
> 
> Is there a way around this?
> J.
> 
> -----Original Message-----
> From: 
> [mailto:] On Behalf Of George Cristian
> Bina
> Sent: 23 October 2009 19:01
> To: Wendell Piez
> Cc: 
> Subject: Re: [oXygen-user] Batch transformations
> 
> Hi Wendell,
> 
> That functionality should be covered now with the support to associate 
> transformation scenarios on the project selected files, including 
> folders. So you can use the "Configure transformation scenario..." 
> action on a folder (or on your selection) and select the scenario then 
> close the dialog with the "Transform now" button if you want the 
> scenario to be applied immediately after closing the dialog. Further you
> 
> can trigger the transformation again with the "Apply transformation 
> scenario" action.
> 
> Thinking now about this I think it may be good to add also the 
> "Transform with..." action back as that allows applying a scenario 
> without associating it with the documents (or folders). Let me know also
> 
> if your use case is not covered by this scenario association that we 
> have in version 11.
> 
> Best Regards,
> George



More information about the oXygen-user mailing list