Skip to content

Instantly share code, notes, and snippets.

@gimsieke
Created February 1, 2022 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gimsieke/739f185a0bb5d032f2999aa5e439a163 to your computer and use it in GitHub Desktop.
Save gimsieke/739f185a0bb5d032f2999aa5e439a163 to your computer and use it in GitHub Desktop.
JATS page numbers
<body>
<sec>
<title><target id="p-3"/>Title<fn>
<p>Footnote, <target id="fnp-4"/>continued</p>
</fn></title>
<p>Text<fn>
<p>Second footnote</p>
</fn>
<target id="p-4"/>flow<fn>
<p>Next footnote</p>
</fn>
<target id="p-5"/> and more text<fn>
<p>Another foot<target id="fnp-6">-</target>note</p>
</fn></p>
</sec>
</body>
<body>
<sec>
<title><target id="p-3"/>[3]Title<fn>
<p>[3]Footnote, <target id="fnp-4"/>[4]continued</p>
</fn></title>
<p>[3]Text<fn>
<p>[4]Second footnote</p>
</fn>[3] <target id="p-4"/>[4]flow<fn>
<p>[4]Next footnote</p>
</fn>[4] <target id="p-5"/>[5] and more text<fn>
<p>[5]Another foot<target id="fnp-6">-</target>[6]note</p>
</fn></p>
</sec>
</body>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/">
<xsl:next-match>
<xsl:with-param name="all-pagebreaks"
as="element(target)*" tunnel="yes"
select="descendant::target[starts-with(@id, 'p-')]"/>
<xsl:with-param name="all-fn-pagebreaks"
as="element(target)*" tunnel="yes"
select="descendant::target[starts-with(@id, 'fnp-')]"/>
</xsl:next-match>
</xsl:template>
<xsl:template match="title/text() | p/text()">
<xsl:call-template name="current-page"/>
<xsl:next-match/>
</xsl:template>
<xsl:template name="current-page">
<xsl:param name="all-pagebreaks" as="element(target)*" tunnel="yes"/>
<xsl:param name="all-fn-pagebreaks" as="element(target)*" tunnel="yes"/>
<xsl:text>[</xsl:text>
<xsl:value-of
select="($all-pagebreaks[. &lt;&lt; current()] |
$all-fn-pagebreaks[. &lt;&lt; current()[ancestor::fn]])[last()]/@id
=> replace('^(fn)?p-', '')"/>
<xsl:text>]</xsl:text>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment