TransformerException when using xsl:import instead of xsl:include

1k views Asked by At

I have a problem with an XSLT / XSL-FO Template when I IMPORT another template:

Main Template looks like this:

<xsl:stylesheet version="2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format"
                              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                                >
<xsl:output method="xml" version="1.0" indent="yes"/>

<xsl:import href="../BAUSTEINE/KopfUndFussteil.xsl" />

<xsl:template match="documentData">
  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
      <!-- Seitendefinition -->
      <fo:simple-page-master page-height="297mm" page-width="210mm"
          margin="5mm 25mm 5mm 25mm" master-name="PageMaster">

        <fo:region-body margin-top="4cm" margin-bottom="4cm" margin-left="1cm" margin-right="1cm"/>

        <fo:region-before extent="1cm"/>

        <fo:region-after extent="1cm"/>
      </fo:simple-page-master>
    </fo:layout-master-set>

    <fo:page-sequence master-reference="PageMaster">

     <fo:static-content flow-name="xsl-region-before">
        <xsl:call-template name="kopf_statisch" />
     </fo:static-content>

     <fo:static-content flow-name="xsl-region-after">
        <xsl:call-template name="fussteil" />
     </fo:static-content>

     <fo:flow flow-name="xsl-region-body" >
        <xsl:call-template name="body" />
     </fo:flow>
    </fo:page-sequence>
  </fo:root>
</xsl:template>

<xsl:template name="kopf_statisch">
    <fo:block></fo:block>
</xsl:template>

<xsl:template name="fussteil">
    <fo:block>
        <xsl:call-template name="KopfUndFussteilEUFZ" />
    </fo:block>
</xsl:template>

<xsl:template name="body">
    <fo:block>Body</fo:block>
</xsl:template>

As you can see, I divided the template into subtemplates (this example here is reduced to the min). In what is called the "fussteil" (pagefoot) I call a template that should be imported from the "KopfUndFussteil.xsl". That one looks like this:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format"
                              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    >


<xsl:template name="KopfUndFussteilEUFZ">
    Block2
</xsl:template>

</xsl:stylesheet>

So quite easy. When I INCLUDE the subtemplate using

<xsl:include href="../BAUSTEINE/KopfUndFussteil.xsl" />

All works fine - no errors occur, "Block2"-Text is rendered into Target PDF

But, when I use

<xsl:import href="../BAUSTEINE/KopfUndFussteil.xsl" />

I get the following error :

javax.xml.transform.TransformerException: ElemTemplateElement-Fehler: KopfUndFussteilEUFZ

So, does anybody have an Idea whats the problem with the import-statement? I am using Xalan 2.7.2

Thanks in advance! Heiko

1

There are 1 answers

1
Martin Honnen On BEST ANSWER

See https://www.w3.org/TR/xslt#import, "The xsl:import element children must precede all other element children of an xsl:stylesheet element" so try moving the xsl:import up before any other child element. Also Xalan is an XSLT 1.0 processor so setting version="2.0" in your code sets it to forwards compatible processing mode which is usually not a good idea to get precise and good error messages.