]> granicus.if.org Git - docbook-dsssl/commitdiff
Support automatic collation of year ranges in copyright
authorNorman Walsh <ndw@nwalsh.com>
Tue, 25 Sep 2001 11:51:18 +0000 (11:51 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Tue, 25 Sep 2001 11:51:18 +0000 (11:51 +0000)
xsl/common/common.xsl
xsl/fo/param.xsl
xsl/fo/titlepage.xsl
xsl/html/param.xsl
xsl/html/titlepage.xsl

index a5d3e255fb2ddcfd7d40dcf8e76863b0f533d98d..21464fc9e71274d73ae7e56d278f452d62bd970a 100644 (file)
@@ -1098,5 +1098,177 @@ pointed to by the link is one of the elements listed in
 
 <!-- ====================================================================== -->
 
+<doc:template name="copyright.years" xmlns="">
+<refpurpose>Print a set of years with collapsed ranges</refpurpose>
+
+<refdescription>
+<para>This template prints a list of year elements with consecutive
+years printed as a range. In other words:</para>
+
+<screen><![CDATA[<year>1992</year>
+<year>1993</year>
+<year>1994</year>]]></screen>
+
+<para>is printed <quote>1992-1994</quote>, whereas:</para>
+
+<screen><![CDATA[<year>1992</year>
+<year>1994</year>]]></screen>
+
+<para>is printed <quote>1992, 1994</quote>.</para>
+
+<para>This template assumes that all the year elements contain only
+decimal year numbers, that the elements are sorted in increasing
+numerical order, that there are no duplicates, and that all the years
+are expressed in full <quote>century+year</quote>
+(<quote>1999</quote> not <quote>99</quote>) notation.</para>
+</refdescription>
+
+<refparameter>
+<variablelist>
+<varlistentry><term>years</term>
+<listitem>
+<para>The initial set of year elements.</para>
+</listitem>
+</varlistentry>
+<varlistentry><term>print.ranges</term>
+<listitem>
+<para>If non-zero, multi-year ranges are collapsed. If zero, all years
+are printed discretely.</para>
+</listitem>
+</varlistentry>
+<varlistentry><term>single.year.ranges</term>
+<listitem>
+<para>If non-zero, two consecutive years will be printed as a range,
+otherwise, they will be printed discretely. In other words, a single
+year range is <quote>1991-1992</quote> but discretely it's
+<quote>1991, 1992</quote>.</para>
+</listitem>
+</varlistentry>
+</variablelist>
+</refparameter>
+
+<refreturn>
+<para>This template returns the formatted list of years.</para>
+</refreturn>
+</doc:template>
+
+<xsl:template name="copyright.years">
+  <xsl:param name="years"/>
+  <xsl:param name="print.ranges" select="1"/>
+  <xsl:param name="single.year.ranges" select="0"/>
+  <xsl:param name="firstyear" select="0"/>
+  <xsl:param name="nextyear" select="0"/>
+
+  <!--
+  <xsl:message terminate="no">
+    <xsl:text>CY: </xsl:text>
+    <xsl:value-of select="count($years)"/>
+    <xsl:text>, </xsl:text>
+    <xsl:value-of select="$firstyear"/>
+    <xsl:text>, </xsl:text>
+    <xsl:value-of select="$nextyear"/>
+    <xsl:text> (</xsl:text>
+    <xsl:value-of select="$years[1]"/>
+    <xsl:text>)</xsl:text>
+  </xsl:message>
+  -->
+
+  <xsl:choose>
+    <xsl:when test="$print.ranges = 0">
+      <xsl:choose>
+        <xsl:when test="count($years) = 1">
+          <xsl:value-of select="$years[1]"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$years[1]"/>
+          <xsl:text>, </xsl:text>
+          <xsl:call-template name="copyright.years">
+            <xsl:with-param name="years"
+                            select="$years[position() &gt; 1]"/>
+            <xsl:with-param name="print.ranges" select="$print.ranges"/>
+            <xsl:with-param name="single.year.ranges"
+                            select="$single.year.ranges"/>
+          </xsl:call-template>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:when>
+    <xsl:when test="count($years) = 0">
+      <xsl:variable name="lastyear" select="$nextyear - 1"/>
+      <xsl:choose>
+        <xsl:when test="$firstyear = 0">
+          <!-- there weren't any years at all -->
+        </xsl:when>
+        <xsl:when test="$firstyear = $lastyear">
+          <xsl:value-of select="$firstyear"/>
+        </xsl:when>
+        <xsl:when test="$single.year.ranges = 0
+                        and $lastyear = $firstyear + 1">
+          <xsl:value-of select="$firstyear"/>
+          <xsl:text>, </xsl:text>
+          <xsl:value-of select="$lastyear"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$firstyear"/>
+          <xsl:text>-</xsl:text>
+          <xsl:value-of select="$lastyear"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:when>
+    <xsl:when test="$firstyear = 0">
+      <xsl:call-template name="copyright.years">
+        <xsl:with-param name="years"
+                        select="$years[position() &gt; 1]"/>
+        <xsl:with-param name="firstyear" select="$years[1]"/>
+        <xsl:with-param name="nextyear" select="$years[1] + 1"/>
+        <xsl:with-param name="print.ranges" select="$print.ranges"/>
+        <xsl:with-param name="single.year.ranges"
+                        select="$single.year.ranges"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="$nextyear = $years[1]">
+      <xsl:call-template name="copyright.years">
+        <xsl:with-param name="years"
+                        select="$years[position() &gt; 1]"/>
+        <xsl:with-param name="firstyear" select="$firstyear"/>
+        <xsl:with-param name="nextyear" select="$nextyear + 1"/>
+        <xsl:with-param name="print.ranges" select="$print.ranges"/>
+        <xsl:with-param name="single.year.ranges"
+                        select="$single.year.ranges"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- we have years left, but they aren't in the current range -->
+      <xsl:choose>
+        <xsl:when test="$nextyear = $firstyear + 1">
+          <xsl:value-of select="$firstyear"/>
+          <xsl:text>, </xsl:text>
+        </xsl:when>
+        <xsl:when test="$single.year.ranges = 0
+                        and $nextyear = $firstyear + 2">
+          <xsl:value-of select="$firstyear"/>
+          <xsl:text>, </xsl:text>
+          <xsl:value-of select="$nextyear - 1"/>
+          <xsl:text>, </xsl:text>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$firstyear"/>
+          <xsl:text>-</xsl:text>
+          <xsl:value-of select="$nextyear - 1"/>
+          <xsl:text>, </xsl:text>
+        </xsl:otherwise>
+      </xsl:choose>
+      <xsl:call-template name="copyright.years">
+        <xsl:with-param name="years"
+                        select="$years[position() &gt; 1]"/>
+        <xsl:with-param name="firstyear" select="$years[1]"/>
+        <xsl:with-param name="nextyear" select="$years[1] + 1"/>
+        <xsl:with-param name="print.ranges" select="$print.ranges"/>
+        <xsl:with-param name="single.year.ranges"
+                        select="$single.year.ranges"/>
+      </xsl:call-template>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 </xsl:stylesheet>
 
index a5c72761a84a842faeafc4893a87751e671342aa..6c4ceeb1541a766cf19e438f2ecb06e525b3a938 100644 (file)
@@ -1264,5 +1264,27 @@ Otherwise, nested fo:blocks will be used.
 </refdescription>
 </doc:param>
 
+<!-- ==================================================================== -->
+<xsl:param name="make.year.ranges" select="0" doc:type="boolean"/>
+
+<doc:param name="make.year.ranges" xmlns="">
+<refpurpose>Collate copyright years into ranges?</refpurpose>
+<refdescription>
+<para>If non-zero, copyright years will be collated into ranges.</para>
+</refdescription>
+</doc:param>
+
+<!-- ==================================================================== -->
+<xsl:param name="make.single.year.ranges" select="0" doc:type="boolean"/>
+
+<doc:param name="make.single.year.ranges" xmlns="">
+<refpurpose>Print single-year ranges (e.g., 1998-1999)</refpurpose>
+<refdescription>
+<para>If non-zero, year ranges that span a single year will be printed
+in range notation (1998-1999) instead of discrete notation
+(1998, 1999).</para>
+</refdescription>
+</doc:param>
+
 </xsl:stylesheet>
 
index d5a299b1d5ea544b1b4525dc36487f34d675110d..d8f5f16ff9da8420828e5a16dd64a2da07fb026f 100644 (file)
 </xsl:template>
 
 <xsl:template match="copyright" mode="titlepage.mode">
-  <xsl:variable name="years" select="year"/>
-  <xsl:variable name="holders" select="holder"/>
-
   <xsl:call-template name="gentext">
     <xsl:with-param name="key" select="'Copyright'"/>
   </xsl:call-template>
     <xsl:with-param name="dingbat">copyright</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="gentext.space"/>
-  <xsl:apply-templates select="$years" mode="titlepage.mode"/>
-  <xsl:if test="holder">
-    <xsl:call-template name="gentext.space"/>
-    <xsl:apply-templates select="$holders" mode="titlepage.mode"/>
-  </xsl:if>
+  <xsl:call-template name="copyright.years">
+    <xsl:with-param name="years" select="year"/>
+    <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
+    <xsl:with-param name="single.year.ranges"
+                    select="$make.single.year.ranges"/>
+  </xsl:call-template>
+  <xsl:call-template name="gentext.space"/>
+  <xsl:apply-templates select="holder" mode="titlepage.mode"/>
 </xsl:template>
 
+
 <xsl:template match="year" mode="titlepage.mode">
   <xsl:apply-templates/><xsl:text>, </xsl:text>
 </xsl:template>
index 1ddc2cd8b510dbcdf630ef454771738608446797..3704d575cec46e3dbe3ee64f85f6f5e9d5de16f1 100644 (file)
@@ -1211,12 +1211,16 @@ will be passed through to the HTML as a class attribute on a
 </refdescription>
 </doc:param>
 
+<!-- ==================================================================== -->
+
 <xsl:param name="olink.fragid" select="'fragid='" doc:type='string'/>
 <xsl:param name="olink.outline.ext" select="'.olink'" doc:type='string'/>
 <xsl:param name="olink.pubid" select="'pubid='" doc:type='string'/>
 <xsl:param name="olink.sysid" select="'sysid='" doc:type='string'/>
 <xsl:param name="olink.resolver" select="'/cgi-bin/olink'" doc:type='string'/>
 
+<!-- ==================================================================== -->
+
 <xsl:param name="shade.verbatim" select="0" doc:type="boolean"/>
 
 <!--
@@ -1236,4 +1240,26 @@ will be passed through to the HTML as a class attribute on a
   <xsl:attribute name="bgcolor">#E0E0E0</xsl:attribute>
 </xsl:attribute-set>
 
+<!-- ==================================================================== -->
+<xsl:param name="make.year.ranges" select="0" doc:type="boolean"/>
+
+<doc:param name="make.year.ranges" xmlns="">
+<refpurpose>Collate copyright years into ranges?</refpurpose>
+<refdescription>
+<para>If non-zero, copyright years will be collated into ranges.</para>
+</refdescription>
+</doc:param>
+
+<!-- ==================================================================== -->
+<xsl:param name="make.single.year.ranges" select="0" doc:type="boolean"/>
+
+<doc:param name="make.single.year.ranges" xmlns="">
+<refpurpose>Print single-year ranges (e.g., 1998-1999)</refpurpose>
+<refdescription>
+<para>If non-zero, year ranges that span a single year will be printed
+in range notation (1998-1999) instead of discrete notation
+(1998, 1999).</para>
+</refdescription>
+</doc:param>
+
 </xsl:stylesheet>
index 9256e4f4dd8ff243a80affde57aa6947df4ce96e..cfa5704a78879ff8db2e35af9b3f6e3a092c3e4e 100644 (file)
 </xsl:template>
 
 <xsl:template match="copyright" mode="titlepage.mode">
-  <xsl:variable name="years" select="year"/>
-  <xsl:variable name="holders" select="holder"/>
-
   <p class="{name(.)}">
     <xsl:call-template name="gentext">
       <xsl:with-param name="key" select="'Copyright'"/>
       <xsl:with-param name="dingbat">copyright</xsl:with-param>
     </xsl:call-template>
     <xsl:call-template name="gentext.space"/>
-    <xsl:apply-templates select="$years" mode="titlepage.mode"/>
-    <xsl:call-template name="gentext.space"/>
-<!--
-    <xsl:call-template name="gentext.by"/>
+    <xsl:call-template name="copyright.years">
+      <xsl:with-param name="years" select="year"/>
+      <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
+      <xsl:with-param name="single.year.ranges"
+                      select="$make.single.year.ranges"/>
+    </xsl:call-template>
     <xsl:call-template name="gentext.space"/>
--->
-    <xsl:apply-templates select="$holders" mode="titlepage.mode"/>
+    <xsl:apply-templates select="holder" mode="titlepage.mode"/>
   </p>
 </xsl:template>