Chain of XSLT

Here should go questions about transforming XML with XSLT and FOP.
ra0543
Posts: 80
Joined: Wed Jan 14, 2009 12:50 pm

Chain of XSLT

Post by ra0543 »

Is it possible to set up a transformation scenario in Oxygen 11 that uses a chained series of XSLT transformations, with each transformation taking as its input the output of the previous transformation, or do I have to do each separately? I have read the help files on setting up scenarios, and I can't tell whether this is possible and if so how to do it.

What I want is, for instance:

INPUT.XML --- with TRANSFORM1.XSL -->
[RESULT1.XML] --- with TRANSFORM2.XSL -->
OUTPUT.XML

I want the two XSLT transformations to be separate. This is because

(a) I want to reuse TRANSFORM1 and potentially follow it in another scenario with a different TRANSFORM2, depending on the final OUTPUT desired.

(b) I am using the TRANSFORM1 to add an attribute to all the relevant elements within the INPUT calculated from their content (identically named but obtained in a different way according to the type of element and what it contains, from either a child element node or from a child attribute node, whichever happens to be present) and then TRANSFORM2 sorts the file on the basis of this newly calculated value (after removing any punctuation, spaces, and capitalisation, and after replacing the æ ligature with ae so that it sorts correctly).

(c) One of the transformations uses XSLT 1.0 and the other 2.0.

I'm not interested in seeing the intermediate stage that is generated (I can get that by running just TRANSFORM1) - I just want to get from INPUT.XML to OUTPUT.XML using successive rather than parallel transformations but in one step for the user.

Is this possible using transformation scenarios and if so, can you set out some very straightforward instructions about where precisely to identify each file when setting up the scenario?
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Chain of XSLT

Post by sorin_ristache »

Hello,

I think the best option is an XProc scripts that describes the sequence of chain transformations. Oxygen 11 has support for editing and running XProc scripts. If you want separate transformations for reusing a transformation in a different scenario I think you should use an Ant build script for sending the output of a transformation as input to the next one because the chain of transformations that you can set in an Oxygen scenario using the Additional XSLT stylesheets button does not allow reusing a step in other scenario.


Regards,
Sorin
siddhi
Posts: 1
Joined: Thu Dec 10, 2009 11:38 am

Re: Chain of XSLT

Post by siddhi »

My query is similar to what ra0543 has posted. I need to run three XSLTs on one input XML, and the sequence followed should be as follows:

FIRST STAGE:
Input file= a.xml
XSLT to be applied=1.xslt
Output should be= a_1.xml

SECOND STAGE:
Input file= a_1.xml
XSLT to be applied=2.xslt
Output should be= a_1_2.xml

THIRD STAGE:
Input file= a_1_2.xml
XSLT to be applied=3.xslt
Output should be= a_1_2_3.xml

I have been able to generate a_1_2_3.xml directly from a.xml through a single click (by creating transformation scenario and applying additional stylesheets into it) but the problem is that <oxygen/> doesn't allow me to save intermediate outputs a_1.xml and a_1_2.xml. It directly takes up the output of one XSLT as input for the other.
I have been suggested to use Xproc, but I am totally new to this term and its use. Please help me!


Thanks very much.
Mircea
Posts: 131
Joined: Tue Mar 25, 2003 11:21 am

Re: Chain of XSLT

Post by Mircea »

Hi,

A simple XProc pipeline for your usecase should look like:

Code: Select all

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step">
<p:input port="source">
<p:document href="a.xml"/>
</p:input>
<p:xslt name="firstStage">
<p:input port="source"/>
<p:input port="stylesheet">
<p:document href="xslt1.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store href="a_1.xml"/>
<p:xslt name="secondStage">
<p:input port="source">
<p:pipe port="result" step="firstStage"/>
</p:input>
<p:input port="stylesheet">
<p:document href="xslt2.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store href="a_1_2.xml"/>
<p:xslt name="thirddStage">
<p:input port="source">
<p:pipe port="result" step="secondStage"/>
</p:input>
<p:input port="stylesheet">
<p:document href="xslt3.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store href="a_1_2_3.xml"/>
</p:declare-step>
Best regards,
Mircea
Mircea Enachescu
<oXygen> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply