首页 文章

XSLT 2.0 - xsl:数字不一致的数字顺序

提问于
浏览
0

在XSLT 2.0中,我将tei:xml文档处理为HTML . 在此过程中,我输出两个脚注的脚注数字,原因有两个 .

首先,通过选择 <sup> (对于上标数字)附加/替换的某些元素,在文本正文中添加数字 .

其次,在页脚 div 中,我创建了一个包含各种注释的相同脚注编号的列表 .

所有这一切都很有效,这在很大程度上要归功于SO的帮助here .

但在测试数百个文档时,我注意到了数字顺序的问题 .

第一步输出 correct order 中的数字(第9-45行) . 第二步输出 wrong order 中的元素(第73-99行) . 这里的XSLT小提琴在HTML视图中简单明了地演示了这一点:https://xsltfiddle.liberty-development.net/jyH9rNj

简单比较一下,输出看起来像这样

body footnote #        footnote div footnote #
     1                          3
     2                          1
     3                          2

我相信这是订单处理的问题,但在尝试通过 modespriority 进行调整后,我无法解决这个问题 . 它似乎与移动 seg 元素之前有一个数字...

很多,非常感谢提前 .

注意: seg/@correspdate 的编号每 <seg> 最多只能出现一次; note 理论上可以出现几次 .

1 回答

  • 2

    我想你想要将变量更正为

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

    因为你不再想要编号 seg 而是 fn-marker ,它们已经被转换为中间步骤 .

    然后你还需要调整模板

    <!-- outputs each item to a <p> in footnote <div> -->
    <xsl:template match="*[. intersect $footnote-sources]" mode="build_footnotes">
        <xsl:choose>    
        <xsl:when test="self::tei:date[@type='deposition_date']">
                <xsl:element name="p">
                    <sup>
                        <xsl:number count="*[. intersect $footnote-sources]" format="1" level="any"/>
                    </sup> this is the foo /date (that should be footnote #1)
                </xsl:element>
            </xsl:when>
            <xsl:when test="self::tei:fn-marker">
                <xsl:element name="p">
                    <sup>
                        <xsl:number count="*[. intersect $footnote-sources]" format="1" level="any"/>
                    </sup> this is the foo seg/@corresp (that should be footnote #3)
                </xsl:element>
            </xsl:when>  
            <xsl:when test="self::tei:note[@type='public']">
                <xsl:element name="p">
                    <sup>
                        <xsl:number count="*[. intersect $footnote-sources]" format="1" level="any"/>
                    </sup> this is the foo /note (that should be number footnote #2)
                </xsl:element>
            </xsl:when>
    
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:template>
    

    那种方式https://xsltfiddle.liberty-development.net/jyH9rNj/1显示

    1 this is the foo /date (that should be footnote #1)
    
    2 this is the foo /note (that should be number footnote #2)
    
    3 this is the foo seg/@corresp (that should be footnote #3)
    

    很明显,“这是foo seg/@corresp 的解释现在有点误导,因为它真的是在转型步骤之前放置的 fn-marker .

相关问题