xsl-list
[Top] [All Lists]

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

2009-11-04 08:18:52
At 2009-11-04 14:12 +0100, Ben Stover wrote:
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?

You can use modes and, in XSLT 2.0, temporary trees, though it will require you to modify the stylesheets and not use them untouched as they exist now. You don't have to use named modes for both steps ... you can use the default unnamed mode for one of the two steps.

The pattern would be along the lines of:

  <xsl:variable name="intermediate">
    <xsl:apply-templates mode="step1"/>
  </xsl:variable>
  <xsl:apply-templates select="$intermediate"/>

or ....

  <xsl:variable name="intermediate">
    <xsl:apply-templates/>
  </xsl:variable>
  <xsl:apply-templates select="$intermediate" mode="step2"/>

... where each stylesheet's template matches are all in the same mode.

Namespace-qualifying your top-level constructs may help too, to avoid overriding declarations.

If you have to do this with XSLT 1 then you'll need to use a vendor-supported extension to act on the node set of the result tree fragment.

I hope this helps.

. . . . . . . . . . . . . Ken

--
Upcoming:  hands-on XSLT, XQuery and XSL-FO Washington DC Nov 2009
Interested in other classes?  http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--