XSLT 2.0 协调多种模式

XSLT 2.0 co-ordinating multiple modes

XSLT 2.0,样式表和数据位于 https://xsltfiddle.liberty-development.net/bFDb2D3/4

我正在将以 tei-xml 编码的中世纪文档转换成网页,用户可以在其中切换文档的两种不同视图,以及查看翻译和各种脚注 (eg) .这需要多层处理才能输出:

我正在使用 modes 来处理处理级别,并且每个模式本身都可以正常工作,但它们一起缺少输出。

应该输出什么:

  1. <div class="inter"><p> 所有转换模式 inter + fn-add-marker [文本中应包含<a href>、上标字母和数字]

  2. <div class="diplo"><p> 所有转换模式 diplo + fn-add-marker [这应该包含 [text] ,行号,上标字母和文本中的数字]

  3. <div><p> 含翻译

  4. <div> 关键设备

  5. <div> 带脚注

XSLTfiddle 输出为:

  1. URL和上标字母ok! 缺少上标数字(模式fn-add-marker
  2. 上标字母ok! Line # 和 [text] ok except where inside <persName> or <placeName> (ie.<xsl:template match="tei:lb"> <xsl:template match="tei:supplied">) and 缺少上标数字(模式fn-add-marker
  3. 好的!
  4. 好的!
  5. 好的!

关于#2,缺失的行 # 和 [text] 似乎是处理 <persName><placeName> 的模板没有移交给其他模板的结果? (第 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 I have tried XSLT to fix your stylesheet and then at https://xsltfiddle.liberty-development.net/bFDb2D3/5您可以看到应用固定样式表的结果。不确定该编程方法是否是正确的工具,但它可能有助于在 xsl:apply-templates.

上演示建议的使用模式 mode

那么我认为您需要确保在两种新模式下处理添加的标记:

<!-- 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 第 51 至 66 行。