On 2017-03-08 Jan Tosovsky wrote:
>
> my HTML output consists of (manually) chunked chapters and sections.
> However, my footnotes are still numbered from the beginning.
>
> I've located the following template in the html/footnote.xsl:
>
> <xsl:template match="footnote" mode="footnote.number">
>
> which implements quite basic counting (simplified here for better
> understanding):
>
> <xsl:variable name="fnum" select="count(preceding::footnote) + 1"/>
>
> Is there a simple way to get actual chunk element inside this template
> and modify the above code to select just 'preceding::footnote' up to
> that chunk element?
>
Once asked another idea came to my mind. And it seems to be a viable
approach...
(1) Using this code I can get unique ID of chunking element:
<xsl:template name="getCurrentChunkElementId">
<xsl:param name="node" select="."/>
<xsl:variable name="isChunk">
<xsl:call-template name="chunk">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$isChunk='1'">
<xsl:value-of select="generate-id($node)"/>
</xsl:when>
<xsl:when test="$node/parent::*">
<xsl:call-template name="getCurrentChunkElementId">
<xsl:with-param name="node" select="$node/parent::*"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>generate-id(/*[1])</xsl:otherwise>
</xsl:choose>
</xsl:template>
(2) In the <xsl:template match="footnote" mode="footnote.number"> template I
use the above code this way:
<xsl:variable name="currentChunkElementId">
<xsl:call-template name="getCurrentChunkElementId"/>
</xsl:variable>
<xsl:variable name="fromBeginning" select="count(preceding::footnote)"/>
<xsl:variable name="fromBeginningUpToCurrentChunk"
select="count(//*[generate-id(.) =
$currentChunkElementId]/preceding::footnote)"/>
<xsl:variable name="fnum" select="$fromBeginning -
$fromBeginningUpToChunk + 1"/>
TODO:
(a) This is simplified demonstration without excluding table footnotes.
(b) That XPath //*[generate-id(.) = $currentChunkElementId] is quite
inefficient and there is mostly likely room for other improvements.
It would be nice to have this numbering system driven by a new HTML
parameter ;-)
Thanks,
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]