RE: [xsl] How to concatenate/merge two independent XSLT stylesheets into ONE stylesheet?

Subject: RE: [xsl] How to concatenate/merge two independent XSLT stylesheets into ONE stylesheet?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 4 Nov 2009 13:51:55 -0000
There are much more efficient ways of creating a pipeline than using "|" on
the command line, but presumably they are ruled out too.

There's no foolproof way of doing this without manually checking for
conflicting names of templates, global variables, keys etc. If you've been
very disciplined then these will all be in namespaces, and it will all be
much easier, but unless you are a very faithful disciple of Ken Holman then
this is unlikely to be the case.

You should change one of the stylesheets (or preferably both) to use named
modes on all template rules and calls of apply-templates.

Then finally you can stitch them together with

<xsl:template match="/">
  <xsl:variable name="temp">
    <xsl:apply-templates select="." mode="phase1"/>
  </xsl:variable>
  <xsl:apply-templates select="$temp" mode="phase2"/>
</xsl:template>

Alternatively, if you don't mind a product-specific solution, use
saxon:next-in-chain on the xsl:output element.

Regards,

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

> 
> I have two independent XSLT style sheets which work fine when 
> they are executed in two steps:
> 
> mydoc1.xml-->mysheet1.xsl-->mydoc2.xml-->mysheet2.xsl-->mydoc3.xml
> 
> However I would like to avoid the intermediate step (and the 
> creation of mydoc2.xml).
> Is there a way to concatenate the two XSLT stylesheets resp. 
> use the output of the first stylesheet templates as input of 
> second stylesheet templates?
> 
> Due to other requirements a piping with the well known pipe 
> symbol (|) on the console is NOT allowed. The two stylesheets 
> MUST be merged together somehow into ONE physical stylesheet file.
> 
> How can I do this?
> 
> Ben

Current Thread