X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/30d14a324bb0e8a99c54cbceea01476e59748b33..bf5758493c7f22bf54ecb7d0f042d4a288d9e2fc:/librarian/xslt/book2html.xslt?ds=inline

diff --git a/librarian/xslt/book2html.xslt b/librarian/xslt/book2html.xslt
index eac63a7..81e865b 100755
--- a/librarian/xslt/book2html.xslt
+++ b/librarian/xslt/book2html.xslt
@@ -508,23 +508,28 @@
 
 <!-- Section headers (included in index)-->
 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
+  <xsl:call-template name="section-anchor"/>
     <h2><xsl:apply-templates mode="inline" /></h2>
 </xsl:template>
 
 <xsl:template match="naglowek_scena|naglowek_rozdzial">
+    <xsl:call-template name="section-anchor"/>
     <h3><xsl:apply-templates mode="inline" /></h3>
 </xsl:template>
 
 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
+      <xsl:call-template name="section-anchor"/>
     <h4><xsl:apply-templates mode="inline" /></h4>
 </xsl:template>
 
 <!-- Other paragraph tags -->
 <xsl:template match="miejsce_czas">
+      <xsl:call-template name="section-anchor"/>
     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
 </xsl:template>
 
 <xsl:template match="didaskalia">
+      <xsl:call-template name="section-anchor"/>
     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
 </xsl:template>
 
@@ -534,14 +539,14 @@
 
 <xsl:template match="akap|akap_dialog|akap_cd">
     <p class="paragraph">
-        <a name="{concat('sect', position())}" />
+      <xsl:call-template name="section-anchor"/>
 	<xsl:apply-templates mode="inline" />
     </p>
 </xsl:template>
 
 <xsl:template match="strofa">
     <div class="stanza">
-      <a name="{concat('sect', position())}" />
+      <xsl:call-template name="section-anchor"/>
         <xsl:choose>
             <xsl:when test="count(br) > 0">
                 <xsl:call-template name="verse">
@@ -716,5 +721,19 @@
     <xsl:value-of select="wl:substitute_entities(.)" />
 </xsl:template>
 
+<!-- ========= -->
+<!-- = utils = -->
+<!-- ========= -->
+<xsl:template name="section-anchor">
+  <!-- 
+       this formula works as follows:
+       - get all ancestors including self
+       - choose the header (third one from root): utwor/book-type/header
+       - get all preceding siblings
+       - count them
+       - create an <a name="sec123"/> tag.
+  -->
+        <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
+</xsl:template>
 
 </xsl:stylesheet>