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

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:05:37

I think, unless you want to prefix all your paths in that template matching / with the variable I suggested to store the result of the marker insertion, one way to merge the existing code with my suggestion is to change the match from / to /* e.g. use

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

that would then mean that my suggestion to use

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

can be kept and the XSLT processor would apply it.

There is however the use of that variable $footnote-sources at the end of the template, as far as I can see from the snippet its use on nodes from the original input document would not be affected by the introduction of a temporary result adding markers but somehow to me it would feel wrong to at that place keep processing the original input while the rest works on the temporary result so I would be inclined to change the variable declaration to

<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]"/>

With those two changes I think my suggestion in the previous answer should then be applied. Although now looking again at the posted source with a tei root element I wonder how a global variable having paths starting with tei:text would select anything but perhaps that is an omission in the sample.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!