XSLT with overlapping elements?

So, the title of this post may be a little misleading, but this is the best I can think of. I am working on a project that uses TEI to encode texts. One of the requirements of my current work is to record XSL transformations for rendering HTML-encoded texts in HTML format. For the most part, there are no problems. I am a bit stuck with this problem:

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

Or, in other cases:

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

(If you are not familiar with TEI: l = line of text, delSpan = range of deleted text that contains more than 1 line, page, or smaller block.)

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

But these singleton tags are an anomaly; all other formatting / markup is done using tags that actually contain the text that they are intended for formatting. Am I right in assuming that I need to handle the delSpan and anchor elements in the "l" pattern? What is the most elegant way to approach this problem and handle pseudo-overlapping elements?

, noob . C/++ XSLT, .

+3
2

:

<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>

: . previus, l. delSpan anchor .

+2

, delSpan "" (anchor ). xml:id.

, , , XSLT 1.0 ( XSLT 2.0). : , anchor xml:id:

<xsl:template match="delSpan">
   <xsl:variable select="@spanTo" name="spanTo" />
   <xsl:apply-templates select="following-sibling::*[following-sibling::anchor[@xml:id = $spanTo]" mode="deleted" />
</xsl:template>

<!--
     do this for all elements you need to treat inside delSpan
     if they have children, remember to use apply-templates with mode deleted
 -->
<xsl:template match="l" mode="deleted">
   <strike><xsl:value-of select="." /></strike>
</xsl:template>

, . , <delSpan> . , .

+1

Source: https://habr.com/ru/post/1759923/


All Articles