带有重叠元素的 XSLT? [英] XSLT with overlapping elements?

查看:22
本文介绍了带有重叠元素的 XSLT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这篇文章的标题可能有点误导,但这是我能想到的最好的.我正在开发一个使用 TEI 编码文本的项目.我当前工作的要求之一是编写 XSL 转换以将 XML 编码的文本呈现为 HTML.大多数情况下,没有问题.不过,我有点困在这个问题上:

So the title of this post may be a little misleading, but it's the best I can come up with. I'm working on a project that uses TEI for encoding texts. One of the requirements of my current work is to write XSL transformations to render the XML-encoded texts as HTML. For the most part, no problem. I'm kind of stuck on this issue, though:

    <l>There is <delSpan spanTo="A1"/>deleted text spanning</l>
    <l>multiple lines here.<anchor xml:id="A1"/> More text...</l>

或者,在其他情况下:

    <delSpan spanTo="A2"/>
    <l>Several deleted lines -- the delspan marker can appear </l>
    <l>outside of an l element.... </l>
    <anchor xml:id="A2"/>

(如果您不熟悉 TEI:l = 一行文本;delSpan = 包含超过 1 行、页面或更小的单位的已删除文本的范围.)

(In case you're not familiar with TEI: l = a line of text; delSpan = span of deleted text that includes more than 1 line, page, or smaller unit.)

目标是显示 delSpan (A1) 与其对应的锚点 (A1) 之间的文本——删除的文本跨越/此处多行"——带有一些指示删除的格式(例如,text-decoration=线通过").现在,有一个用于处理大多数文本格式的l"元素模板——或者至少调用其他模板来完成.

The goal is to display the text between the delSpan (A1) and its corresponding anchor (A1) -- "deleted text spanning / multiple lines here" -- with some formatting that indicates the deletion (e.g., text-decoration="line-through"). Right now, there's a template for "l" elements that handles most text formatting--or at least calls other templates to do it.

但是这些单例标签是异常的;所有其他格式/标记都是通过标签完成的,这些标签实际上包含它们要格式化的文本.我是否正确假设我需要处理l"模板中的 delSpan 和锚元素?解决这个问题和处理伪重叠元素的最优雅的方法是什么?

But these singleton tags are an anomaly; all other formatting/markup is accomplished with tags that actually contain the text they're meant to format. Am I right in assuming that I need to process the delSpan and anchor elements in the "l" template? What's the most elegant way to approach this problem and handle the pseudo-overlapping elements?

对不起,如果这是一个菜鸟问题或者我没有提供足够的信息.我主要是一个 C/C++ 程序员,几乎没有 XSLT 经验,所以我很感激任何建议.

Sorry if this is a noob question or if I haven't given enough information. I'm primarily a C/C++ programmer with little XSLT experience, so I appreciate any suggestions.

推荐答案

此样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="delSpan|anchor"/>
    <xsl:template match="text()[preceding::delSpan[1]/@spanTo=following::anchor[1]/@xml:id]">
        <span style="text-decoration:line-through;">
            <xsl:value-of select="."/>
        </span>
    </xsl:template>
</xsl:stylesheet>

输出:

<doc>
    <l>There is <span style="text-decoration:line-through;">deleted text spanning</span></l>
    <l><span style="text-decoration:line-through;">multiple lines here.</span> More text...</l>
</doc>

注意:前后轴的使用及其在文档顺序中的含义.我们不会覆盖任何与 l 元素匹配的以前的模板.delSpananchor 也无法条带化.

Note: The use of preceding and following axis and their meaning in document order. We don't overrides any previus template matching l elements. delSpan and anchor could also not been striped.

这篇关于带有重叠元素的 XSLT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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