[xsl] Resetting footnotes not working

Subject: [xsl] Resetting footnotes not working
From: "Mark Giffin m1879@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 Jul 2023 06:59:33 -0000
I'm running XSL-FO through Antenna House to make PDF. I need to reset footnote numbers to 1 on every page. I'm using the AH "area tree" XML because it contains the page breaks. My examples below are simplified. A footnote number in the input XML look like <TextArea text="2"/>.

INPUT XML:
<AreaRoot>
B B B  <PageViewportArea>
B B B B B B B  ...
B B B  </PageViewportArea>
B B B  <PageViewportArea>
B B B B B B B  <PageReferenceArea>
B B B B B B B B B B B  <RegionViewportArea>
B B B B B B B B B B B B B B B  <RegionReferenceArea>
B B B B B B B B B B B B B B B B B B B  <MainReferenceArea>
B B B B B B B B B B B B B B B B B B B B B B B  ...
B B B B B B B B B B B B B B B B B B B  </MainReferenceArea>
B B B B B B B B B B B B B B B B B B B  <FootnoteReferenceArea>
B B B B B B B B B B B B B B B B B B B B B B B  <FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  <BlockArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B  ...
B B B B B B B B B B B B B B B B B B B B B B B B B B B  </BlockArea>
B B B B B B B B B B B B B B B B B B B B B B B  </FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B  <FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  <ListBlockArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B  <TextArea text="2"/>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  </ListBlockArea>
B B B B B B B B B B B B B B B B B B B B B B B  </FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B  <FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  <ListBlockArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B  <TextArea text="3"/>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  </ListBlockArea>
B B B B B B B B B B B B B B B B B B B B B B B  </FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B  <FootnoteArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  <ListBlockArea>
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B  <TextArea text="4"/>
B B B B B B B B B B B B B B B B B B B B B B B B B B B  </ListBlockArea>
B B B B B B B B B B B B B B B B B B B B B B B  </FootnoteArea>
B B B B B B B B B B B B B B B B B B B  </FootnoteReferenceArea>
B B B B B B B B B B B B B B B  </RegionReferenceArea>
B B B B B B B B B B B  </RegionViewportArea>
B B B B B B B B B B B  <RegionViewportArea>
B B B B B B B B B B B B B B B  <RegionReferenceArea>
B B B B B B B B B B B B B B B B B B B  <BlockArea/>
B B B B B B B B B B B B B B B  </RegionReferenceArea>
B B B B B B B B B B B  </RegionViewportArea>
B B B B B B B  </PageReferenceArea>
B B B  </PageViewportArea>
</AreaRoot>

---------------
XSLT 2.0:
<xsl:template match="@*|node()">
B B B B B B B  <xsl:copy>
B B B B B B B B B B B  <xsl:apply-templates select="@*|node()"/>
B B B B B B B  </xsl:copy>
B B B  </xsl:template>

B B B <xsl:template match="FootnoteReferenceArea/FootnoteArea/ListBlockArea/TextArea/@text">
B B B B B B B <xsl:variable name="this-page-fns" select="ancestor::FootnoteReferenceArea/FootnoteArea/ListBlockArea/TextArea/@text"/>
B B B B B B B <xsl:call-template name="fix-fn-num">
B B B B B B B B B B B <xsl:with-param name="footnotes" select="$this-page-fns"/>
B B B B B B B </xsl:call-template>
B B B </xsl:template>


B B B  <xsl:template name="fix-fn-num">
B B B B B B B  <xsl:param name="footnotes"/>
B B B B B B B  <xsl:for-each select="$footnotes">
B B B B B B B B B B B  <xsl:choose>
B B B B B B B B B B B B B B B  <xsl:when test="position() = 1">
B B B B B B B B B B B B B B B B B B B  <xsl:attribute name="text">1</xsl:attribute>
B B B B B B B B B B B B B B B  </xsl:when>
B B B B B B B B B B B B B B B  <xsl:when test="position() = 2">
B B B B B B B B B B B B B B B B B B B  <xsl:attribute name="text">2</xsl:attribute>
B B B B B B B B B B B B B B B  </xsl:when>
B B B B B B B B B B B B B B B  <xsl:when test="position() = 3">
B B B B B B B B B B B B B B B B B B B  <xsl:attribute name="text">3</xsl:attribute>
B B B B B B B B B B B B B B B  </xsl:when>
B B B B B B B B B B B B B B B  <xsl:otherwise>
B B B B B B B B B B B B B B B B B B B  <xsl:attribute name="text">ERROR</xsl:attribute>
B B B B B B B B B B B B B B B  </xsl:otherwise>
B B B B B B B B B B B  </xsl:choose>
B B B B B B B  </xsl:for-each>
B B B  </xsl:template>

---------------
But the output footnotes are all the same number like this:
<RegionReferenceArea>
B B B  <MainReferenceArea>
B B B B B B B  ...
B B B  </MainReferenceArea>
B B B  <FootnoteReferenceArea>
B B B B B B B  <FootnoteArea>
B B B B B B B B B B B  <BlockArea>
B B B B B B B B B B B B B B B  ...
B B B B B B B B B B B  </BlockArea>
B B B B B B B  </FootnoteArea>
B B B B B B B  <FootnoteArea>
B B B B B B B B B B B  <ListBlockArea>
B B B B B B B B B B B B B B B  <TextArea text="3"/>
B B B B B B B B B B B  </ListBlockArea>
B B B B B B B  </FootnoteArea>
B B B B B B B  <FootnoteArea>
B B B B B B B B B B B  <ListBlockArea>
B B B B B B B B B B B B B B B  <TextArea text="3"/>
B B B B B B B B B B B  </ListBlockArea>
B B B B B B B  </FootnoteArea>
B B B B B B B  <FootnoteArea>
B B B B B B B B B B B  <ListBlockArea>
B B B B B B B B B B B B B B B  <TextArea text="3"/>
B B B B B B B B B B B  </ListBlockArea>
B B B B B B B  </FootnoteArea>
B B B  </FootnoteReferenceArea>
</RegionReferenceArea>

Is there a better way to do this? I think it needs some kind of recursion.

Thanks,
Mark

Current Thread