XSLT 2.0 - xsl:number 不一致的数字顺序
XSLT 2.0 - xsl:number inconsistent number order
在 XSLT 2.0 中,我将 tei:xml 文档处理为 HTML。在此过程中,出于两个原因,我分两次输出脚注编号。
首先,通过选择 attached/replaced by <sup>
(对于上标数字)的某些元素,在正文本身中添加数字。
其次,在页脚 div
我创建了一个包含相同脚注编号和不同注释的列表。
所有这一切都很好,这在很大程度上要感谢在 SO 上收到的帮助 here。
但是在测试数百个文档的过程中,我发现了一个编号顺序问题。
第一步以正确的顺序输出数字(第9-45行)。第二步输出错序的元素(第73-99行)。 XSLT fiddle 此处在 HTML 视图中简单明了地演示了这一点:https://xsltfiddle.liberty-development.net/jyH9rNj
进行简单比较,输出结果如下
body footnote # footnote div footnote #
1 3
2 1
3 2
我认为这是订单处理的问题,但在尝试通过 modes
和 priority
进行调整后,我无法解决这个问题。这似乎与在给它一个数字之前移动 seg
元素有关...
非常非常感谢。
注意:seg/@corresp
和 date
的数字每 <seg>
最多只能出现一次; note
理论上可以出现多次
我想你想将变量更正为
<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
放在转换步骤之前。
在 XSLT 2.0 中,我将 tei:xml 文档处理为 HTML。在此过程中,出于两个原因,我分两次输出脚注编号。
首先,通过选择 attached/replaced by <sup>
(对于上标数字)的某些元素,在正文本身中添加数字。
其次,在页脚 div
我创建了一个包含相同脚注编号和不同注释的列表。
所有这一切都很好,这在很大程度上要感谢在 SO 上收到的帮助 here。
但是在测试数百个文档的过程中,我发现了一个编号顺序问题。
第一步以正确的顺序输出数字(第9-45行)。第二步输出错序的元素(第73-99行)。 XSLT fiddle 此处在 HTML 视图中简单明了地演示了这一点:https://xsltfiddle.liberty-development.net/jyH9rNj
进行简单比较,输出结果如下
body footnote # footnote div footnote #
1 3
2 1
3 2
我认为这是订单处理的问题,但在尝试通过 modes
和 priority
进行调整后,我无法解决这个问题。这似乎与在给它一个数字之前移动 seg
元素有关...
非常非常感谢。
注意:seg/@corresp
和 date
的数字每 <seg>
最多只能出现一次; note
理论上可以出现多次
我想你想将变量更正为
<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
放在转换步骤之前。