XSLT 2.0 - xsl:number inconsistent number order

83 Views Asked by At

In XSLT 2.0 I am processing tei:xml documents to HTML. During this process I output footnote numbers in two passes, for two reasons.

First, adding numbers in the text body itself by selecting certain elements to which are attached/replaced by <sup> (for superscript numbers).

Second, in the footer div I create a list of those same footnote numbers with various notes.

All of this works great, thanks in large part to the help received here on SO.

But during testing through the hundreds of documents, I noticed a problem of number order.

The first step outputs the numbers in the correct order (lines 9-45). The second step outputs the elements in the wrong order (lines 73-99). XSLT fiddle here demonstrates this simply and clearly in HTML view: https://xsltfiddle.liberty-development.net/jyH9rNj

Put in simple comparison, the output looks like this

body footnote #        footnote div footnote #
     1                          3
     2                          1
     3                          2

I believe this is a question of order processing, but after attempting to adjust it through modes and priority I have not been able to solve this. It seems to have to do with moving the seg element before giving it a number...

Many, many thanks in advance.

NB: the number for seg/@corresp and date can only ever appear once each per <seg> maximum; note can theoretically appear several times.

1

There are 1 best solutions below

0
On BEST ANSWER

I think you want to correct the variable to

<xsl:variable name="footnote-sources" select="$fn-markers-added//tei:date[@type='deposition_date'] |                            
            $fn-markers-added//tei:note[@type='public'] | $fn-markers-added//tei:fn-marker"/>

as you no longer want to number the segs but rather the fn-markers they have been transformed to in the intermediary step.

Then you also need to adjust the template to

<!-- outputs each item to a <p> in footnote <div> -->
<xsl:template match="*[. intersect $footnote-sources]" mode="build_footnotes">
    <xsl:choose>    
    <xsl:when test="self::tei:date[@type='deposition_date']">
            <xsl:element name="p">
                <sup>
                    <xsl:number count="*[. intersect $footnote-sources]" format="1" level="any"/>
                </sup> this is the foo /date (that should be footnote #1)
            </xsl:element>
        </xsl:when>
        <xsl:when test="self::tei:fn-marker">
            <xsl:element name="p">
                <sup>
                    <xsl:number count="*[. intersect $footnote-sources]" format="1" level="any"/>
                </sup> this is the foo seg/@corresp (that should be footnote #3)
            </xsl:element>
        </xsl:when>  
        <xsl:when test="self::tei:note[@type='public']">
            <xsl:element name="p">
                <sup>
                    <xsl:number count="*[. intersect $footnote-sources]" format="1" level="any"/>
                </sup> this is the foo /note (that should be number footnote #2)
            </xsl:element>
        </xsl:when>

        <xsl:otherwise/>
    </xsl:choose>
</xsl:template>

That ways https://xsltfiddle.liberty-development.net/jyH9rNj/1 shows

1 this is the foo /date (that should be footnote #1)

2 this is the foo /note (that should be number footnote #2)

3 this is the foo seg/@corresp (that should be footnote #3)

obviously the explanation "this is the foo seg/@corresp is a bit misleading now as it is really a fn-marker placed earlier the transformation step.