这个问题建立在对我的original question的回复上,在那里有人建议我发布一个跟进。这涉及到尝试集成上一篇文章中的XSL代码。
在上一个问题中,我给出了使用XSLT2.0转换成HTML :XML文档的简化版本(完整的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>
中创建的:
date[@type="deposition_date"]
(添加脚注编号),seg[@type="typefoo"]
(添加脚注编号) note[@type="public_note"]
(替换为脚注编号)。期望输出
<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上找到,在那里可以看到以下问题:
date[@type='deposition_date']
将被完全替换,而不是接收添加的脚注markerseg[@type='dep_event' and @corresp]
不会接收添加的脚注标记,但它会出现在页面底部的<div>
中。XSL文件太长,似乎不能正确粘贴到此处。与此处的文件交互https://xsltfiddle.liberty-development.net/bdxtqT/6。
注意:我只能使用XSLT 2.0,因为这种转换是在使用Xquery 3.1的eXist-DB中触发的。
非常感谢!
发布于 2018-10-18 02:31:56
我认为,除非您想使用我建议的变量作为模板中匹配/
的所有路径的前缀,以存储标记插入的结果,否则将现有代码与我的建议合并的一种方法是将匹配从/
更改为/*
,例如使用
<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
开头的全局变量如何选择任何内容,但这可能是示例中的一个遗漏。
https://stackoverflow.com/questions/52860271
复制相似问题