XSLT 2.0 通过多阶段转换在 HTML 输出中创建增量脚注编号

XSLT 2.0 creating incremental footnote numbers in HTML output through multi-stage transformation

这个问题建立在对我 的回复之上,有人建议我 post 跟进。这涉及尝试集成来自先前 post 的 XSL 代码。

在上一个问题中,我介绍了 TEI:XML 文档的简化版本,我正在使用 XSLT 2.0 将其转换为 HTML(完整的 tei 文件和当前的 xslt 可以在此处找到 https://xsltfiddle.liberty-development.net/bdxtqT/6).这是层次结构的完整视图,但不是所有细节:

<tei>
 <teiHeader/>
 <text>
   <front/>
   <body>
     <p xml:lang="LA">
       <seg type="typefoo" corresp="#foo601" xml:id="foo361">
         <date type="deposition_date" when="1245">Idus 
         marcii</date>In non hendrerit metus. Sed in posuere 
         eros, sit amet pharetra lacus.</seg>
       <seg type="typefoo" xml:id="foo362">Nullam semper varius 
         justo, vitae mollis turpis dapibus sit amet. 
         Donec<note type="public_note">note content</note> 
         rhoncus tempor urna sit amet imperdiet.</seg>
       <seg type="typefoo" xml:id="foo363">Integer 
         id ante nunc. Curabitur at ligula sed arcu consequat 
         gravida et id orci. Morbi quis porta dolor.</seg>
       <seg type="typefoo" corresp="#fooid2">Sed dictum<note 
         type="public_note">note content 2</note> sem nec urna sodales 
         cursus. Donec sit amet nibh tempor, congue ligula semper, 
         rhoncus odio.</seg>
     </p>
   </body>
   <back>
     <p xml:lang="EN">
       <seg>
       <seg>
     </p>
     <p xml:lang="FR">
       <seg>
       <seg>
     </p>
   </back>
 </text>     
<tei>

所需的HTML输出如下。根据以下三个条件之一在 <sup> 中创建增量脚注编号:

期望的输出

 <div>
   <p>Idus marcii<sup>1</sup>In non hendrerit metus. Sed in 
       posuere eros, sit amet pharetra lacus.</p><sup>2</sup>
   <p>Nullam semper varius justo, vitae mollis turpis 
       dapibus sit amet. Donec<sup>3</sup> rhoncus tempor 
       urna sit amet imperdiet.</p>
   <p>Integer id ante nunc. Curabitur at ligula sed 
       arcu consequat gravida et id orci. Morbi quis porta 
       dolor.</p>
   <p>Sed dictum sem<sup>4</sup> nec urna sodales cursus. 
      Donec sit amet nibh tempor, congue ligula semper, 
      rhoncus odio.</p><sup>5</sup>
  <div>

  [...]

 <div>
   <p><sup>1</sup> 1245</p>
   <p><sup>2</sup> foo601</p>
   <p><sup>3</sup> note here</p>
   <p><sup>4</sup> note here</p>
   <p><sup>5</sup> fooid2</p>
  </div>

完整的 XSLT 转换文档可在 https://xsltfiddle.liberty-development.net/bdxtqT/6 找到,其中可以看到以下问题:

XSL 文件太长,似乎无法正确粘贴到此处。在此处与文件交互 https://xsltfiddle.liberty-development.net/bdxtqT/6.

注意:我仅限于 XSLT 2.0,因为此转换是在 eXist-DB 中使用 Xquery 3.1 触发的。

非常感谢!

我认为,除非您想在该模板中匹配 / 的所有路径加上我建议存储标记插入结果的变量前缀,否则将现有代码与我的建议合并的一种方法是将匹配项从 / 更改为 /* 例如使用

<xsl:template match="/*">
        <!-- div for text -->
        <div>
            <!-- LATIN : always present -->
            <h3>Latin</h3>
            <xsl:apply-templates select="//tei:body//tei:p"/>

            <!-- ENGLISH : always present -->
            <h3>English</h3>
            <xsl:apply-templates select="//tei:back//tei:p[@xml:lang='EN']"/>

            <!-- FRENCH : sometimes present -->
            <xsl:if test="//tei:back//tei:p[@xml:lang='FR']">
                <h3>French</h3>
                <xsl:apply-templates select="//tei:back//tei:p[@xml:lang='FR']"/>
            </xsl:if>
            <!-- FOOTER for notes -->
            <div class="footer">

            <!-- FOOTNOTES (uses mode="build_footnotes" to construct a block of footnotes in <div>) -->
               <xsl:if test="$footnote-sources">
                 <div class="footnotes" id="footnotesdiv">
                     <xsl:apply-templates select="$footnote-sources" mode="build_footnotes"/>
                 </div>
               </xsl:if>
            </div>
        </div>
</xsl:template>

那就意味着我建议使用

<xsl:template match="/">
    <xsl:apply-templates select="$fn-markers-added/node()"/>
</xsl:template>

可以保留,XSLT 处理器将应用它。

然而,在模板末尾使用了该变量 $footnote-sources,据我从代码片段中可以看出,它在原始输入文档的节点上的使用不会受到引入的影响临时结果添加标记但不知何故对我来说,在那个地方继续处理原始输入而其余的工作在临时结果上会感觉不对所以我倾向于将变量声明更改为

<xsl:variable name="footnote-sources" select="$fn-markers-added/tei:text//tei:seg//date[@type='deposition_date'] | 
    $fn-markers-added/tei:text//tei:seg//note[@type='public_note'] | $fn-markers-added/tei:text//tei:seg[@corresp]"/>

通过这两项更改,我认为应该应用我在上一个答案中的建议。虽然现在再次查看带有 tei 根元素的已发布源代码,但我想知道具有以 tei:text 开头的路径的全局变量如何 select 任何东西,但也许这是示例中的一个遗漏。