【问题标题】:XInclude in XSLT Stylesheets (eXist-db)X包含在 XSLT 样式表中 (eXist-db)
【发布时间】:2023-03-19 00:55:02
【问题描述】:

我的一些样式表有点大,而且它们的某些部分是重复的。我想为它们使用 XInclude——这将允许我将它们与整个样式表分开。我不能在这里使用xsl:importxsl:include,因为我需要将它们注入到生成书签和活动链接的特定位置(对于 XSL-FO)。

如果我使用:

<xi:include href="/db/apps/tested-bunny/resources/xsl-fo/common/bookmark-tree.xml/>

...生成的.fo 文件确实包含该部分。但是,该部分是未翻译的,这意味着它与源代码一样存在。 XSL-FO 处理器因此会忽略它,并且 pdf 结果没有书签。

至于分离的部分——我将它保存为一个常规 XML 文件,并在根元素中声明了两个命名空间:

<fo:bookmark-tree xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:if test="$head-level ge '1'">
    ...

如果我尝试在 XSL 样式表中包含相同的代码 sn-p,它是一样的——它被正确地注入到那里,但它没有将其功能添加到整个样式表中,它仍然没有被翻译。

是否有任何我不知道的具体做法或限制?如何正确地做到这一点?

【问题讨论】:

    标签: xslt exist-db xinclude


    【解决方案1】:

    对我来说,可行的解决方案不是 XInclude 而是 xsl:include 并在适当的时间调用模板:

    ...
    </fo:declarations>
    <!-- Bookmarks from the external stylesheet -->
    <xsl:call-template name="bookmark-tree"/>
    <fo:page-sequence master-reference="title-page">
    ...
    

    我创建了正确的样式表。重要的是将根元素设置为当前上下文:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="2.0">
        <xsl:template name="bookmark-tree" match=".">
            <fo:bookmark-tree>
                ...
    

    当然,有必要将样式表包含在我调用模板的那个中:

    <xsl:include href="common/bookmark-tree.xsl"/>
    

    目前,我认为这个问题已得到解答。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 2015-12-19
      相关资源
      最近更新 更多