XSLT 2.0 协调多种模式 [英] XSLT 2.0 co-ordinating multiple modes
问题描述
XSLT 2.0,样式表和数据位于 https://xsltfiddle.liberty-development.net/bFDb2D3/4
我正在将用 tei-xml 编码的中世纪文档转换成网页,用户可以在其中切换文档的两种不同视图,以及查看翻译和各种脚注 (例如).这需要多层处理才能输出:
- 用户可以在两个拉丁版本('inter' 和 'diplo')之间切换(源自相同的 tei 标记)
- 几乎没有转换的翻译版本(只有段落格式和斜体)
- 使用脚注#a、b、c 等的关键装置
- 使用脚注 # 1、2、3 等的历史脚注.
我使用 modes
来处理处理级别,每个模式本身都可以正常工作,但它们一起缺少输出.
应该输出什么:
<div class="inter"><p>
带有所有转换模式inter
+fn-add-marker代码>[这应该包含
,文本中的上标字母和数字]
<div class="diplo"><p>
带有所有转换模式diplo
+fn-add-marker代码>[这应该包含 [text] 、行号、上标字母和文本中的数字]
带翻译
带关键装置带脚注XSLTfiddle 输出是:
- 网址和上标字母都可以!缺少上标数字(模式
fn-add-marker
) - 上标字母可以!第 # 行和 [text] ok 除了在
或
内的地方(即
)<xsl:template match="tei:supplied">
) 和缺少上标数字(模式<代码>fn-add-marker - 好的!
- 好的!
- 好的!
关于#2,缺少的行#和[text]似乎是处理
和
的模板的结果不移交给其他模板?(第 173-218 行的模板)所有关于
fn-add-marker
模式的模板都在第 41-77 行.非常感谢.
解决方案基本上在 XSLT 2 中,一旦您使用命名模式,您需要确保模板中属于某个模式,例如
mode="foo"
,您使用例如mode="foo"
或更通用的mode="#current"
在任何xsl:apply-templates
里面,以确保处理在该模式下继续.请参阅 https://www.w3.org/TR/xslt20/#element-apply-templates 了解详情.在 https://xsltfiddle.liberty-development.net/gWmuiK7 我试过了XSLT 修复您的样式表,然后在 https://xsltfiddle.liberty-development.net/bFDb2D3/5 可以看到应用固定样式表的结果.不确定这种编程方法是否是正确的工具,但它可能有助于在
xsl:apply-templates
上演示建议的使用模式mode
.那么我认为您需要确保在两种新模式中处理添加的标记:
<xsl:template match="tei:date[@type='deposition_date']" mode="inter dilpo"><xsl:apply-templates mode="#current"/><xsl:apply-templates select="."模式=数字"/></xsl:模板><xsl:template match="tei:note[@type='public'] | tei:fn-marker" mode="inter diplo"><xsl:apply-templates select="."模式=数字"/></xsl:模板><xsl:template match="tei:date[@type='deposition_date'] | tei:note[@type='public'] | tei:fn-marker" mode="number"><sup><xsl:number count="tei:date[@type='deposition_date'] | tei:note[@type='public'] | tei:fn-marker" format="1" level="any"/></sup></xsl:模板><!-- 脚注转换结束-->
https://xsltfiddle.liberty-development.net/bFDb2D3/6第 51 到 66 行.
XSLT 2.0, stylesheet and data at https://xsltfiddle.liberty-development.net/bFDb2D3/4
I am transforming medieval documents encoded in tei-xml into webpages where the user can toggle between two different views of the documents, as well as see the translation and various footnotes (eg). This requires multiple layers of processing to output:
- Two latin versions ('inter' and 'diplo') between which the user can toggle (derived from the same tei markup)
- Translated version with almost no transformations (just paragraph formatting and italics)
- Critical apparatus using footnoting # a, b, c, etc.
- Historical footnotes using footnoting # 1, 2, 3, etc.
I am using
modes
in order to handle the levels of processing, and each mode on its own works fine, but together they are missing outputs.What should output:
<div class="inter"><p>
with all transformations modeinter
+fn-add-marker
[this should contain<a href>
, superscript letters and numbers in text]<div class="diplo"><p>
with all transformations modediplo
+fn-add-marker
[this should contain [text] , line numbers, superscript letters and numbers in text]<div><p>
with translations<div>
with critical apparatus<div>
with footnotes
The XSLTfiddle output is:
- URL and superscript letters ok! missing superscript numbers (mode
fn-add-marker
) - Superscript letters ok! Line # and [text] ok except where inside
<persName>
or<placeName>
(ie.<xsl:template match="tei:lb">
<xsl:template match="tei:supplied">
) and missing superscript numbers (modefn-add-marker
) - ok!
- ok!
- ok!
With respect to #2, the missing line # and [text] appear to be a result of the templates that treat
<persName>
and<placeName>
not handing off to other templates? (templates at lines 173-218)All templates concerning mode
fn-add-marker
are at lines 41-77.Many thanks in advance.
解决方案Basically in XSLT 2, once you work with named modes, you need to make sure in a template belonging to a certain mode, having e.g.
mode="foo"
, that you use e.g.mode="foo"
or more generalmode="#current"
on anyxsl:apply-templates
inside to ensure processing continues in that mode. See https://www.w3.org/TR/xslt20/#element-apply-templates for details.At https://xsltfiddle.liberty-development.net/gWmuiK7 I have tried XSLT to fix your stylesheet and then at https://xsltfiddle.liberty-development.net/bFDb2D3/5 you can see the result of applying the fixed stylesheet. Not sure whether that programmatic approach is the right tool but it might help to demonstrate the suggested use mode
mode
onxsl:apply-templates
.Then I think you need to make sure you process the added markers in the two new modes:
<!-- adds fn numbers --> <xsl:template match="tei:date[@type='deposition_date']" mode="inter dilpo"> <xsl:apply-templates mode="#current"/> <xsl:apply-templates select="." mode="number"/> </xsl:template> <xsl:template match="tei:note[@type='public'] | tei:fn-marker" mode="inter diplo"> <xsl:apply-templates select="." mode="number"/> </xsl:template> <xsl:template match="tei:date[@type='deposition_date'] | tei:note[@type='public'] | tei:fn-marker" mode="number"> <sup> <xsl:number count="tei:date[@type='deposition_date'] | tei:note[@type='public'] | tei:fn-marker" format="1" level="any"/> </sup> </xsl:template> <!-- end of footnote transformations -->
https://xsltfiddle.liberty-development.net/bFDb2D3/6 lines 51 to 66.
这篇关于XSLT 2.0 协调多种模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文