Skip to content

Commit

Permalink
better page handling
Browse files Browse the repository at this point in the history
  • Loading branch information
glorieux-f committed Jun 14, 2024
1 parent e1e5056 commit 7eaac6d
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions docx/tei_tmpl.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -281,39 +281,45 @@ s#</(bg|color|font|mark)_[^>]+>#</hi>#g
</xsl:copy>
</xsl:template>
<!-- Page number -->
<xsl:template match="tei:pb[text()]">
<xsl:variable name="n" select="translate(., '[]p.  ', '')"/>
<xsl:template match="tei:pb">
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="normalize-space(@n) != ''">
<xsl:value-of select="normalize-space(@n)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="n" select="number(translate($value, '[]p.  ', ''))"/>
<xsl:choose>
<xsl:when test="number($n) &gt; 0">
<pb n="{$n}">
<xsl:when test="$n &gt; 0">
<pb>
<xsl:copy-of select="@*"/>
<xsl:attribute name="xml:id">
<xsl:value-of select="concat('p', $n)"/>
</xsl:attribute>
<xsl:attribute name="n">
<xsl:value-of select="$n"/>
</xsl:attribute>
</pb>
</xsl:when>
<xsl:when test="contains(., '###')">
<pb n="###"/>
</xsl:when>
<xsl:otherwise>
<pb n="{normalize-space(translate(., '[]', ''))}"/>
<pb>
<xsl:copy-of select="@*"/>
<xsl:if test="not(@n) and $value != ''">
<xsl:attribute name="n">
<xsl:value-of select="$value"/>
</xsl:attribute>
</xsl:if>
</pb>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Auto numbering, especially page-break-before generated by ABBYY -->
<xsl:template match="tei:pb[not(text())][not(@n)]">
<pb>
<xsl:copy-of select="@*"/>
<!-- No auto numbering, is false from life docx
<xsl:attribute name="n">
<xsl:variable name="n">
<xsl:number level="any"/>
</xsl:variable>
<xsl:value-of select="$n - 1 + $pb"/>
</xsl:attribute>
-->
</pb>
</xsl:template>
<!-- Notes candidates -->
<xsl:template match="tei:ref[translate(., '[]()1234567890', '')=''][starts-with(@target, '#Footnote')]">
<xsl:variable name="id" select="id(substring-after(@target, '#'))"/>
Expand All @@ -333,8 +339,16 @@ s#</(bg|color|font|mark)_[^>]+>#</hi>#g
</xsl:template>
<xsl:template match="tei:ref[starts-with(., 'p.') or starts-with(., '[p.')]">
<pb>
<xsl:variable name="n" select="number(translate(., '[]p.  ', ''))"/>
<xsl:attribute name="n">
<xsl:value-of select="translate(normalize-space(.), '[]', '')"/>
<xsl:choose>
<xsl:when test="$n > 0">
<xsl:value-of select="$n"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(normalize-space(.), '[]', '')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="facs">
<xsl:value-of select="normalize-space(@target)"/>
Expand Down

0 comments on commit 7eaac6d

Please sign in to comment.