I have three xsl files and one input file:
-input.xml process1.xsl output1.xml
-output1.xml process2.xsl output3.xml
now i want to just have it as:
input.xml process.xslt output.xml
process1.xsl, process2.xsl and their outputs should passed as the input to the xsl file and generate output.xml in the same process.xsl file.
how do i do this in xslt , i have referred to xslt apply imports but i am not getting proper reference for assigning the xml output as input for another xsl file all in one xsl.. can anyone help me out?
here i have invoked the input.xml and used process1.xsl for first step and the output generated is stored in the $content variable now i am stuck here that how do i import the process2.xsl and assing it to the previous output in variable $content, i am just able to display its output i want to assing it to next xsl file:
<xsl:import href="process1.xsl"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="content">
<xsl:apply-imports/>
</xsl:variable>
<xsl:apply-templates select="exsl:node-set($content)/*" mode="m"/>
</xsl:template>
<xsl:template match="@*|*|text()" mode="m">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="@*|*|text()" mode="m"/>
</xsl:copy>
</xsl:template>
something like this but this does not work?
Using XSLT 3.0 you could use the
fold-left
function (https://www.w3.org/TR/xpath-functions-31/#func-fold-left) together with thetransform
function (https://www.w3.org/TR/xpath-functions-31/#func-transform) to chain the transformations:Obviously in a real transformation your stylesheet would do more than outputting a comment to indicate its processing the input but using above stylesheet called with Saxon 9.7 EE and
-it -xsl:process.xsl
, where the input isand the two stylesheets
process1.xsl
andprocess2.xsl
are for instancethe output is
so the chaining is working.
Instead of passing the input document as a parameter you could also provide it as the primary input
-s
and change the main stylesheet toIf you want to chain transformations with Java then see https://stackoverflow.com/a/35845231/252228 for an example.