使用 xsl:import 而不是 xsl:include 时出现 TransformerException

TransformerException when using xsl:import instead of xsl:include

我在导入另一个模板时遇到 XSLT/XSL-FO 模板问题:

主模板如下所示:

<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>

正如你所看到的,我把模板分成了子模板(这里的这个例子被缩小到最小)。在所谓的 "fussteil"(pagefoot)中,我调用了一个应该从 "KopfUndFussteil.xsl" 导入的模板。那个看起来像这样:

<?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>

非常简单。当我 INCLUDE 子模板使用

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

一切正常 - 没有发生错误,"Block2"- 文本呈现为目标 PDF

但是,当我使用

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

我收到以下错误:

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

那么,有人知道导入语句有什么问题吗?我正在使用 Xalan 2.7.2

提前致谢!黑子

请参阅 https://www.w3.org/TR/xslt#import、"The xsl:import element children must precede all other element children of an xsl:stylesheet element",因此尝试将 xsl:import 向上移动到任何其他子元素之前。此外,Xalan 是一个 XSLT 1.0 处理器,因此在您的代码中设置 version="2.0" 会将其设置为转发兼容处理模式,这通常不是获得准确和良好错误消息的好主意。