XSLT 2.0 协调多种模式 [英] XSLT 2.0 co-ordinating multiple modes

查看:29
本文介绍了XSLT 2.0 协调多种模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

  • 用户可以在两个拉丁版本('inter' 和 'diplo')之间切换(源自相同的 tei 标记)
  • 几乎没有转换的翻译版本(只有段落格式和斜体)
  • 使用脚注#a、b、c 等的关键装置
  • 使用脚注 # 1、2、3 等的历史脚注.

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

应该输出什么:

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

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

XSLTfiddle 输出是:

  1. 网址和上标字母都可以!缺少上标数字(模式fn-add-marker)
  2. 上标字母可以!第 # 行和 [text] ok 除了在 内的地方(即 <xsl:template match="tei:supplied">) 和缺少上标数字(模式<代码>fn-add-marker)
  3. 好的!
  4. 好的!
  5. 好的!

关于#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:

  1. <div class="inter"><p> with all transformations mode inter + fn-add-marker [this should contain <a href>, superscript letters and numbers in text]

  2. <div class="diplo"><p> with all transformations mode diplo + fn-add-marker [this should contain [text] , line numbers, superscript letters and numbers in text]

  3. <div><p> with translations

  4. <div> with critical apparatus

  5. <div> with footnotes

The XSLTfiddle output is:

  1. URL and superscript letters ok! missing superscript numbers (mode fn-add-marker)
  2. 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 (mode fn-add-marker)
  3. ok!
  4. ok!
  5. 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 general mode="#current" on any xsl: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 on xsl: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆