Re: [xsl] Pipelining 2 stylesheets

Subject: Re: [xsl] Pipelining 2 stylesheets
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 27 Aug 2009 18:28:42 +0200
Martynas Jusevicius wrote:

I want to pipeline 2 templates opendoc2xhtml.xsl (from OpenOffice) and
xhtml2epub.xsl (my own) into a single opendoc2epub, that is, to pass
the result of the first one into the second one.
As I understand, the common technique is to get the first result into
a variable, and then run the second transformation on it (assuming
XSLT 2).

But I have a problem with including the stylesheets. If i try to
xsl:include both templates and define a template for the root node, I
get a conflict, because opendoc2xhtml also has one. And I don't want
to add modes or anything to it because it comes from an external
source, but I still need to override it somehow to put the result into
a variable in the first place.
Is it where xsl:import is used? I tried importing opendoc2xhtml.xsl as
well and calling xsl:apply-imports from the root template, but then
only root children were processed.

Have you tried to match on e.g. document-node(element(foo)) and document-node(element(bar)) where foo would be the root element type of the first input and bar would be the root element type of the temporary result?


Along these lines (you will need to change that for the real root element name of opendoc, I am not familiar with that format):

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:x="http://www.w3.org/1999/xhtml";
  version="2.0">

  <xsl:import href="opendoc2xhtml.xsl"/>
  <xsl:include href="xhtml2epub.xsl"/>

  <xsl:template match="document-node(element(opendocrootname))">
    <xsl:variable name="temp">
      <xsl:apply-imports/>
    </xsl:variable>
    <xsl:apply-templates select="$temp"/>
  </xsl:template>

  <xsl:template match="document-node(element(x:html))">
    <xsl:next-match/>
  </xsl:template>

</xsl:stylesheet>


--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread