forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r106785 - /forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl /forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl
Date Sun, 28 Nov 2004 03:51:03 GMT
Author: rick
Date: Sat Nov 27 19:51:02 2004
New Revision: 106785

URL: http://svn.apache.org/viewcvs?view=rev&rev=106785
Log:
Lots of changes.  Was on a roll. :)

Note to self: Create documentation for this plugin that highlights the
features and discusses some of the limitations (ie. table cells have min
width of 10)

The big changes are:

  * Lists with hanging indents
  * Nested lists
  * Tables
  * Nested Tables
  * Lists in Tables
  * Tables in Lists (I think)
  * Better handling of in-line elements, in particluar the spacing
    before and after such elements.
  * source elements are indented nicely.

The gory details:

- Handle nested lists by including a width parameter that is called from
  the table templates

- Handle the padding of the table cells.  This just required not
  including padding if we were at a muitiple of the cell width.

- The wrapping of the text in the table cells is handled by the applied
  templates.  Just needed to pass the correct width to wrap on, which is
  the colwidth - 2.  The '2' is for the padding in the cells.

- Emit the whole table at once.  This will allow for tables to be in
  lists or other tables

- Handle em, strong and code in-line elements and proper spacing after
  such elements

- Correct some usage of passing in the level parameter.  A number of
  elements were incrementing the level for no reason

- Added CR for abstract and notice sections;  cleaned up extraneous w/s

- trailing space issue when a text node consists purely of white space.
  Such a string will have a null trailing-space variable defined.
  Cleans up some of the issues with in-line elements and odd padding
  behaviour in definition lists.

- Handle source element separately from p[@xml:space='preserve']
  elements.  The source element will be emitted with the current
  indentation.  No such liberty will be taken with the xml:space
  preserve.

- Removed width paramenter from the emit-with-indent template.  It is
  not used.  Width considerations are handled by the wrap-text()
  template instead.

- Renamed emit() to wrap-text().

- Handled trailing-space in adding it to the text-remaining variable in
  order to carry the trailing-space forward through recursive calls to
  wrap-text().

- Move the responsibility of emit()'ing carriage returns to the element
  being handled rather than doing it in emit() directly.

  This has the benefit of finer control in how line spacing is done,
  especially when nested lists are involved.

- Handle nested lists nicely with proper indent.

- Change the indentation of notes, warnings, fixmes to be zero when
  embedded within a list.

- Added an emit-with-indent() that handles markers for dealing with
  ordered and unordered lists with hanging indents

Modified:
   forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl
   forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl

Modified: forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl
Url: http://svn.apache.org/viewcvs/forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl?view=diff&rev=106785&p1=forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl&r1=106784&p2=forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl&r2=106785
==============================================================================
--- forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl	(original)
+++ forrest/trunk/plugins/text-output/resources/stylesheets/common/text-templates.xsl	Sat Nov 27 19:51:02 2004
@@ -18,8 +18,7 @@
 
   <!-- A single carriage return -->
   <xsl:template name="cr">
-    <xsl:text>
-</xsl:text>
+    <xsl:text>&#xa;</xsl:text>
   </xsl:template>
 
   <!-- A blank line -->
@@ -76,26 +75,55 @@
     </xsl:choose>
   </xsl:template>
 
-  <xsl:template name="emit">
+  <!-- Takes a block of text, normalizes all the spaces, carriage returns
+    etc.  It then word wraps to a specified width after indenting each
+    line -->
+
+  <xsl:template name="wrap-text">
     <xsl:param name="text"/>
     <xsl:param name="indent"/>
-    <xsl:param name="width" select="'76'"/>
+    <xsl:param name="width" select="$document-width"/>
+    <xsl:param name="fixed" select="false"/>
 
     <!-- FIXME: Handle case when ($width - $indent) less than 1 -->
     <xsl:variable name="work-width" select="$width - $indent"/>
 
     <!-- We'll lose whether the text had a trailing space when we
-    normalize-space() it.  Needed if we're combining multiple outputs
-    of emit() into a single variable and then re-emitting ... -->
+    normalize-space() it.  Needed to preserve the space between
+    a text() node and in-line markup.  For example
+
+      <p>This text is the text node and <strong>this is in-line
+      markup</strong>.  We want to preserve the space between
+      the first text node and the "strong" markup.</p>
+
+    A string that consists purely of white space will have the trailing-space
+    variable set to ''.
+    -->
+
     <xsl:variable name="trailing-space">
-      <xsl:if test="substring($text, string-length($text))=' '">
-        <xsl:text> </xsl:text>
-      </xsl:if>
+      <xsl:choose>
+        <xsl:when test="normalize-space($text)!=''">
+          <xsl:if test="substring($text, string-length($text))=' '">
+            <xsl:text> </xsl:text>
+          </xsl:if>
+        </xsl:when>
+        <xsl:otherwise/>
+      </xsl:choose>
     </xsl:variable>
 
     <!-- Normalized text.  We'll use this for calculations on
-    splitting, lengths, etc. -->
-    <xsl:variable name="ntext" select="normalize-space($text)"/>
+    splitting, lengths, etc.  If we're emitting based on fixed
+    width text, do not normalize-space() the incoming text -->
+    <xsl:variable name="ntext">
+      <xsl:choose>
+        <xsl:when test="$fixed">
+          <xsl:value-of select="$text"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="normalize-space($text)"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
 
     <xsl:choose>
       <xsl:when test="string-length($ntext) > $work-width">
@@ -124,8 +152,8 @@
         <xsl:value-of select="$text-wrap"/>
         <xsl:call-template name="cr"/>
 
-        <xsl:call-template name="emit">
-          <xsl:with-param name="text" select="$text-remaining"/>
+        <xsl:call-template name="wrap-text">
+          <xsl:with-param name="text" select="concat($text-remaining,$trailing-space)"/>
           <xsl:with-param name="indent" select="$indent"/>
           <xsl:with-param name="width" select="$width"/>
         </xsl:call-template>
@@ -135,7 +163,83 @@
           <xsl:with-param name="size" select="$indent"/>
         </xsl:call-template>
         <xsl:value-of select="concat($ntext,$trailing-space)"/>
-        <xsl:call-template name="cr"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <!-- Prefixes each line of a block of text with necessary indent,
+    markers (bullets, item numbers) and additional hanging indent.
+
+    It does absolutely no word-wrapping as it is assumed that this
+    has already been done. -->
+
+  <xsl:template name="emit-with-indent">
+    <xsl:param name="text"/>
+    <xsl:param name="indent"/>
+    <xsl:param name="marker" select="''"/>
+    <xsl:param name="first-line" select="1"/>
+
+    <xsl:variable name="marker-length" select="string-length($marker)"/>
+    <xsl:variable name="tmp" select="substring-before($text,'&#xa;')"/>
+
+    <xsl:choose>
+      <xsl:when test="contains($text,'&#xa;')">
+
+        <!-- Determine the text to emit.  If it's the first line, include
+             include the indentation marker.  Otherwise, include 
+             an equivalent amount of blank space to replace the
+             marker used in the first line.  This will create a
+             hanging indent -->
+
+        <xsl:variable name="text-to-emit">
+          <xsl:call-template name="lineOf">
+            <xsl:with-param name="size" select="$indent"/>
+            <xsl:with-param name="chars" select="' '"/>
+          </xsl:call-template>
+          <xsl:choose>
+            <xsl:when test="$first-line">
+              <xsl:value-of select="$marker"/>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:call-template name="lineOf">
+                <xsl:with-param name="size" select="$marker-length"/>
+              </xsl:call-template>
+            </xsl:otherwise>
+          </xsl:choose>
+          <xsl:value-of select="$tmp"/>
+        </xsl:variable>
+
+        <xsl:value-of select="concat($text-to-emit,'&#xa;')"/>
+        
+        <xsl:variable name="text-remaining"
+                    select="substring($text, string-length($tmp)+2)"/>
+
+        <xsl:call-template name="emit-with-indent">
+          <xsl:with-param name="text" select="$text-remaining"/>
+          <xsl:with-param name="indent" select="$indent"/>
+          <xsl:with-param name="marker" select="$marker"/>
+          <xsl:with-param name="first-line" select="0"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:variable name="text-to-emit">
+          <xsl:call-template name="lineOf">
+            <xsl:with-param name="size" select="$indent"/>
+          </xsl:call-template>
+          <xsl:choose>
+            <xsl:when test="$first-line">
+              <xsl:value-of select="$marker"/>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:call-template name="lineOf">
+                <xsl:with-param name="size" select="$marker-length"/>
+              </xsl:call-template>
+            </xsl:otherwise>
+          </xsl:choose>
+          <xsl:value-of select="$text"/>
+        </xsl:variable>
+
+        <xsl:value-of select="concat($text-to-emit,'&#xa;')"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
@@ -144,10 +248,31 @@
   <xsl:template name="text-to-last-space">
     <xsl:param name="text"/>
 
-    <xsl:variable name="leading" select="substring-before($text, ' ')"/>
-    <xsl:variable name="remaining" select="substring-after($text,' ')"/>
+    <xsl:variable name="leading">
+      <xsl:choose>
+        <xsl:when test="contains($text,' ')"> 
+          <xsl:value-of select="substring-before($text, ' ')"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$text"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:variable name="remaining">
+      <xsl:choose>
+        <xsl:when test="contains($text,' ')"> 
+          <xsl:value-of select="substring-after($text, ' ')"/>
+        </xsl:when>
+        <xsl:otherwise/>
+      </xsl:choose>
+    </xsl:variable>
 
-    <xsl:value-of select="concat($leading,' ')"/>
+    <xsl:value-of select="$leading"/>
+    <!-- Emit the space if we had one to begin with -->
+    <xsl:if test="contains($text,' ')">
+      <xsl:text> </xsl:text>
+    </xsl:if>
 
     <xsl:choose>
       <xsl:when test="contains($remaining,' ')">
@@ -157,6 +282,616 @@
       </xsl:when>
       <xsl:otherwise/>
     </xsl:choose>
+  </xsl:template>
+
+  <!-- ==================================================================== -->
+  <!--  Table Handling
+
+        The column widths are calculated automatically based on a maximum
+        width, "maxwidth" (default 76),  that the table can be .  This maxiumum
+        width is used only for the calculation of the column widths.  These
+        column widths cannot be less than the "mincolwidth" (default 10).
+
+        If the calculated column widths are less than the "mincolwidth", the
+        table is grown horizontally based on the "mincolwidth" and the max
+        number of columns.
+
+        An idententation paramenter, "indent" (default 4) is used since pod2man
+        does a default indentation of 4 for verbatim text.  This value is used
+        in the calculation of the column widths.
+  -->
+  <!-- ==================================================================== -->
+
+  <xsl:template match="table">
+    <xsl:param name="level">1</xsl:param>
+    <xsl:param name="mincolwidth">10</xsl:param>
+    <xsl:param name="width" select="$document-width"/>
+    <xsl:variable name="cols">
+      <xsl:value-of select="count(tr[1]/th|tr[1]/td)"/>
+    </xsl:variable>
+
+    <xsl:variable name="indent" select="$level * $indent-per-level"/>
+    <xsl:variable name="maxwidth" select="$width - $indent"/>
+
+    <xsl:variable name="calc-colwidth">
+      <xsl:value-of select="floor(($maxwidth - $indent - $cols) div $cols) - 1"/>
+    </xsl:variable>
+
+    <xsl:variable name="colwidth">
+      <xsl:choose>
+        <xsl:when test="$mincolwidth > $calc-colwidth">
+          <xsl:value-of select="$mincolwidth"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$calc-colwidth"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:variable name="caption-text">
+      <xsl:apply-templates select="caption" mode="in-list">
+        <xsl:with-param name="level" select="$level"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$caption-text"/>
+      <xsl:with-param name="indent" select="$indent"/>
+    </xsl:call-template>
+
+    <xsl:variable name="the-table">
+      <xsl:apply-templates select="tr" mode="in-list">
+        <xsl:with-param name="level" select="$level"/>
+        <xsl:with-param name="colwidth" select="$colwidth"/>
+        <xsl:with-param name="cols" select="$cols"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$the-table"/>
+      <xsl:with-param name="indent" select="$indent"/>
+    </xsl:call-template>
+
+    <xsl:call-template name="newLine"/>
+
+  </xsl:template>
+
+  <xsl:template match="table" mode="in-list">
+    <xsl:param name="level">0</xsl:param>
+    <xsl:param name="mincolwidth">10</xsl:param>
+    <xsl:param name="width" select="$document-width"/>
+    <xsl:variable name="cols">
+      <xsl:value-of select="count(tr[1]/th|tr[1]/td)"/>
+    </xsl:variable>
+
+    <xsl:variable name="indent" select="$level * $indent-per-level"/>
+    <xsl:variable name="maxwidth" select="$width - $indent"/>
+
+    <xsl:variable name="calc-colwidth">
+      <xsl:value-of select="floor(($maxwidth - $indent - $cols) div $cols) - 1"/>
+    </xsl:variable>
+
+    <xsl:variable name="colwidth">
+      <xsl:choose>
+        <xsl:when test="$mincolwidth > $calc-colwidth">
+          <xsl:value-of select="$mincolwidth"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$calc-colwidth"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:variable name="caption-text">
+      <xsl:apply-templates select="caption" mode="in-list">
+        <xsl:with-param name="level" select="$level"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$caption-text"/>
+      <xsl:with-param name="indent" select="$indent"/>
+    </xsl:call-template>
+
+    <xsl:variable name="the-table">
+      <xsl:apply-templates select="tr" mode="in-list">
+        <xsl:with-param name="level" select="$level"/>
+        <xsl:with-param name="colwidth" select="$colwidth"/>
+        <xsl:with-param name="cols" select="$cols"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$the-table"/>
+      <xsl:with-param name="indent" select="$indent"/>
+    </xsl:call-template>
+
+    <xsl:call-template name="newLine"/>
+
+  </xsl:template>
+
+  <xsl:template match="caption" mode="in-list">
+    <xsl:param name="level"/>
+    <xsl:apply-templates/>
+  </xsl:template>
+    
+  <xsl:template match="tr" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="colwidth"/>
+    <xsl:param name="cols"/>
+
+    <xsl:variable name="dashes">
+      <xsl:call-template name="lineOf">
+        <xsl:with-param name="size" select="'80'"/>
+        <xsl:with-param name="chars" select="'-'"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:variable name="cell-border">
+      <xsl:value-of select="substring( $dashes, 1, $colwidth )"/>
+    </xsl:variable>
+    
+    <xsl:variable name="row-border">
+      <xsl:call-template name="make-row-border">
+        <xsl:with-param name="col">1</xsl:with-param>
+        <xsl:with-param name="colwidth" select="$colwidth"/>
+        <xsl:with-param name="maxcols" select="$cols"/>
+        <xsl:with-param name="cell-border" select="$cell-border"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:value-of select="$row-border"/>
+    <xsl:call-template name="cr"/>
+
+    <!-- Can we handle a dynamic number of columns?  Not sure how to
+         do that, so just limit the number we can handle to some reasonable
+         maximum.  Currently, that maximum is 10 -->
+
+    <!-- For the current row, grab the content for each cell in this row.
+         The content will be fit by the "handle-cell-content" template.  -->
+
+    <xsl:variable name="col-1">
+      <xsl:if test="(th|td)[1]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[1]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-2">
+      <xsl:if test="(th|td)[2]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[2]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-3">
+      <xsl:if test="(th|td)[3]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[3]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-4">
+      <xsl:if test="(th|td)[4]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[4]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-5">
+      <xsl:if test="(th|td)[5]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[5]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-6">
+      <xsl:if test="(th|td)[6]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[6]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-7">
+      <xsl:if test="(th|td)[7]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[7]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-8">
+      <xsl:if test="(th|td)[8]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[8]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-9">
+      <xsl:if test="(th|td)[9]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[9]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="col-10">
+      <xsl:if test="(th|td)[10]">
+        <xsl:variable name="tmp">
+          <xsl:apply-templates select="(th|td)[10]" mode="in-list">
+            <xsl:with-param name="width" select="$colwidth - 2"/>
+          </xsl:apply-templates>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:variable>
+
+    <!--
+      Okay, so we've got the contents of the cells for a single row.
+      Let's pass this off to emit-table-row where we can extract
+      $colwidth from each column and emit until we're out of content
+    -->
+
+    <xsl:call-template name="emit-table-row">
+      <xsl:with-param name="maxcols" select="$cols"/>
+      <xsl:with-param name="colwidth" select="$colwidth"/>
+      <xsl:with-param name="col-1" select="$col-1"/>
+      <xsl:with-param name="col-2" select="$col-2"/>
+      <xsl:with-param name="col-3" select="$col-3"/>
+      <xsl:with-param name="col-4" select="$col-4"/>
+      <xsl:with-param name="col-5" select="$col-5"/>
+      <xsl:with-param name="col-6" select="$col-6"/>
+      <xsl:with-param name="col-7" select="$col-7"/>
+      <xsl:with-param name="col-8" select="$col-8"/>
+      <xsl:with-param name="col-9" select="$col-9"/>
+      <xsl:with-param name="col-10" select="$col-10"/>
+    </xsl:call-template>
+
+    <xsl:if test="position()=last()">
+      <xsl:value-of select="$row-border"/>
+      <xsl:call-template name="cr"/>
+    </xsl:if>
+
+  </xsl:template>
+
+  <xsl:template match="td|th" mode="in-list">
+    <xsl:param name="width"/>
+
+    <xsl:apply-templates mode="in-list">
+      <xsl:with-param name="width" select="$width"/>
+      <xsl:with-param name="level" select="'0'"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template name="make-row-border">
+    <xsl:param name="col"/>
+    <xsl:param name="colwidth"/>
+    <xsl:param name="maxcols"/>
+    <xsl:param name="cell-border"/>
+    <xsl:param name="border">+</xsl:param>
+
+    <xsl:choose>
+      <xsl:when test="$col > $maxcols">
+        <xsl:value-of select="$border"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="make-row-border">
+          <xsl:with-param name="col" select="$col + 1"/>
+          <xsl:with-param name="maxcols" select="$maxcols"/>
+          <xsl:with-param name="cell-border" select="$cell-border"/>
+          <xsl:with-param name="border"
+              select="concat($border, $cell-border, '+')"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <!-- emit-table-row
+
+       Recursive template to keep extracting content from each of the
+       columns, emit a single line in each cell, until all the content
+       is used up
+  -->
+
+  <xsl:template name="emit-table-row">
+    <xsl:param name="maxcols"/>
+    <xsl:param name="colwidth"/>
+    <xsl:param name="col-1"/>
+    <xsl:param name="col-2"/>
+    <xsl:param name="col-3"/>
+    <xsl:param name="col-4"/>
+    <xsl:param name="col-5"/>
+    <xsl:param name="col-6"/>
+    <xsl:param name="col-7"/>
+    <xsl:param name="col-8"/>
+    <xsl:param name="col-9"/>
+    <xsl:param name="col-10"/>
+
+    <xsl:text>| </xsl:text>
+    <xsl:call-template name="make-cell">
+      <xsl:with-param name="content" select="$col-1"/>
+      <xsl:with-param name="colwidth" select="$colwidth"/>
+    </xsl:call-template>
+
+    <xsl:if test="$maxcols > 1">
+
+      <xsl:text> | </xsl:text>
+      <xsl:call-template name="make-cell">
+        <xsl:with-param name="content" select="$col-2"/>
+        <xsl:with-param name="colwidth" select="$colwidth"/>
+      </xsl:call-template>
+
+      <xsl:if test="$maxcols > 2">
+
+        <xsl:text> | </xsl:text>
+        <xsl:call-template name="make-cell">
+          <xsl:with-param name="content" select="$col-3"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+
+        <xsl:if test="$maxcols > 3">
+
+          <xsl:text> | </xsl:text>
+          <xsl:call-template name="make-cell">
+            <xsl:with-param name="content" select="$col-4"/>
+            <xsl:with-param name="colwidth" select="$colwidth"/>
+          </xsl:call-template>
+
+          <xsl:if test="$maxcols > 4">
+
+            <xsl:text> | </xsl:text>
+            <xsl:call-template name="make-cell">
+              <xsl:with-param name="content" select="$col-5"/>
+              <xsl:with-param name="colwidth" select="$colwidth"/>
+            </xsl:call-template>
+
+            <xsl:if test="$maxcols > 5">
+
+              <xsl:text> | </xsl:text>
+              <xsl:call-template name="make-cell">
+                <xsl:with-param name="content" select="$col-6"/>
+                <xsl:with-param name="colwidth" select="$colwidth"/>
+              </xsl:call-template>
+
+              <xsl:if test="$maxcols > 6">
+
+                <xsl:text> | </xsl:text>
+                <xsl:call-template name="make-cell">
+                  <xsl:with-param name="content" select="$col-7"/>
+                  <xsl:with-param name="colwidth" select="$colwidth"/>
+                </xsl:call-template>
+
+                <xsl:if test="$maxcols > 7">
+
+                  <xsl:text> | </xsl:text>
+                  <xsl:call-template name="make-cell">
+                    <xsl:with-param name="content" select="$col-8"/>
+                    <xsl:with-param name="colwidth" select="$colwidth"/>
+                  </xsl:call-template>
+
+                  <xsl:if test="$maxcols > 8">
+
+                    <xsl:text> | </xsl:text>
+                    <xsl:call-template name="make-cell">
+                      <xsl:with-param name="content" select="$col-9"/>
+                      <xsl:with-param name="colwidth" select="$colwidth"/>
+                    </xsl:call-template>
+
+                    <xsl:if test="$maxcols > 9">
+
+                      <xsl:text> | </xsl:text>
+                      <xsl:call-template name="make-cell">
+                        <xsl:with-param name="content" select="$col-10"/>
+                        <xsl:with-param name="colwidth" select="$colwidth"/>
+                      </xsl:call-template>
+
+                    </xsl:if>
+                  </xsl:if>
+                </xsl:if>
+              </xsl:if>
+            </xsl:if>
+          </xsl:if>
+        </xsl:if>
+      </xsl:if>
+    </xsl:if>
+
+    <xsl:text> |</xsl:text>
+    <xsl:call-template name="cr"/>
+
+    <!-- Determine whether there is any content left in any of the
+         cells on this row.  If so, we need to call emit-table-row again -->
+
+    <xsl:variable name="content-remains">
+      <xsl:if test="string-length(substring($col-1, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-2, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-3, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-4, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-5, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-6, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-7, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-8, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-9, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+      <xsl:if test="string-length(substring($col-10, $colwidth - 2)) > 1">
+        <xsl:text>1</xsl:text>
+      </xsl:if>
+    </xsl:variable>
+
+    <xsl:if test="string-length($content-remains) > 0">
+      <xsl:call-template name="emit-table-row">
+        <xsl:with-param name="maxcols" select="$maxcols"/>
+        <xsl:with-param name="colwidth" select="$colwidth"/>
+        <xsl:with-param name="col-1"
+            select="substring( $col-1, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-2" 
+            select="substring( $col-2, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-3"
+            select="substring( $col-3, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-4"
+            select="substring( $col-4, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-5"
+            select="substring( $col-5, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-6"
+            select="substring( $col-6, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-7" 
+            select="substring( $col-7, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-8"
+            select="substring( $col-8, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-9"
+            select="substring( $col-9, $colwidth - 2 + 1 )"/>
+        <xsl:with-param name="col-10"
+            select="substring( $col-10, $colwidth - 2 + 1 )"/>
+      </xsl:call-template>
+    </xsl:if>
+
+  </xsl:template>
+
+  <xsl:template name="make-cell">
+    <xsl:param name="content"/>
+    <xsl:param name="colwidth"/>
+
+    <xsl:variable name="padding">
+      <xsl:call-template name="lineOf">
+        <xsl:with-param name="size" select="'80'"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:variable name="cell">
+      <xsl:choose>
+        <xsl:when test="$colwidth - 2 > string-length($content)">
+
+          <!-- The subtraction of 2 is for the border padding.  It is reflected
+               in the call to make-cell in the "content" parameter -->
+
+          <xsl:value-of select="concat($content,
+               substring($padding,1,$colwidth - 2 - string-length($content)))"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="substring($content, 1, $colwidth - 2)"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:value-of select="$cell"/>
+  </xsl:template>
+
+  <!--  handle-cell-content
+
+        Replaces any new-line characters found in the content with 
+        an appropriate number of spaces to fill out the cell to the
+        end of the cell and another number of spaces to fill out a 
+        "blank" line.
+  -->
+
+  <xsl:template name="handle-cell-content">
+    <xsl:param name="text"/>
+    <xsl:param name="colwidth"/>
+
+    <xsl:variable name="spaces">
+      <xsl:call-template name="lineOf">
+        <xsl:with-param name="size" select="'80'"/>
+        <xsl:with-param name="chars" select="' '"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:choose>
+      <xsl:when test="contains( $text, '&#xa;' )">
+        <xsl:variable name="text-before">
+          <xsl:value-of select="substring-before( $text, '&#xa;' )"/>
+        </xsl:variable>
+        <xsl:variable name="tmp">
+          <xsl:value-of select="$text-before"/>
+
+          <!-- Pad only if the length of the text we've emitted is not
+               a multiple of the unpadded column width ($colwidth - 2). -->
+          <xsl:if test="(string-length($text-before) mod ($colwidth - 2))!=0">
+            <xsl:value-of select="substring( $spaces, 1,
+                ($colwidth - 2) - (string-length($text-before) mod ($colwidth -2)))"/>
+          </xsl:if>
+          <xsl:value-of select="substring-after($text, '&#xa;')"/>
+        </xsl:variable>
+        <xsl:call-template name="handle-cell-content">
+          <xsl:with-param name="text" select="$tmp"/>
+          <xsl:with-param name="colwidth" select="$colwidth"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$text"/>
+      </xsl:otherwise>
+    </xsl:choose>
+
   </xsl:template>
 
 </xsl:stylesheet>

Modified: forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl
Url: http://svn.apache.org/viewcvs/forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl?view=diff&rev=106785&p1=forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl&r1=106784&p2=forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl&r2=106785
==============================================================================
--- forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl	(original)
+++ forrest/trunk/plugins/text-output/resources/stylesheets/txt/document2txt.xsl	Sat Nov 27 19:51:02 2004
@@ -25,7 +25,7 @@
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
   <xsl:import href="../common/text-templates.xsl"/>
-                
+
   <xsl:param name="dynamic-page" select="'false'"/>  
   <xsl:param name="notoc"/>
   <xsl:param name="path"/>
@@ -75,7 +75,7 @@
       <xsl:text>; </xsl:text>
     </xsl:if>
     <xsl:apply-templates select="version"/>
-    
+
   </xsl:template>
 
   <xsl:template match="header/authors">
@@ -103,11 +103,12 @@
       </xsl:apply-templates>
     </xsl:variable>
 
-    <xsl:call-template name="emit">
+    <xsl:call-template name="wrap-text">
       <xsl:with-param name="text" select="$para"/>
       <xsl:with-param name="indent" select="$level * $indent-per-level"/>
       <xsl:with-param name="width" select="$document-width"/>
     </xsl:call-template>
+    <xsl:call-template name="cr"/>
   </xsl:template>
 
   <xsl:template match="abstract">
@@ -125,11 +126,12 @@
       </xsl:apply-templates>
     </xsl:variable>
 
-    <xsl:call-template name="emit">
+    <xsl:call-template name="wrap-text">
       <xsl:with-param name="text" select="$para"/>
       <xsl:with-param name="indent" select="$level * $indent-per-level"/>
       <xsl:with-param name="width" select="$document-width"/>
     </xsl:call-template>
+    <xsl:call-template name="cr"/>
   </xsl:template>
 
   <!-- Handle the body bits -->
@@ -138,114 +140,19 @@
       <xsl:with-param name="level" select="'0'"/>
     </xsl:apply-templates>
   </xsl:template>
-  
-  <xsl:template match="p[@xml:space='preserve']|source">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:value-of select="."/>
-    <xsl:call-template name="cr"/>
-  </xsl:template>
-  
-  <xsl:template match="p">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:call-template name="cr"/>
-
-    <xsl:variable name="para">
-      <xsl:apply-templates>
-        <xsl:with-param name="level" select="$level"/>
-      </xsl:apply-templates>
-    </xsl:variable>
-
-    <xsl:call-template name="emit">
-      <xsl:with-param name="text" select="$para"/>
-      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
-      <xsl:with-param name="width" select="$document-width"/>
-    </xsl:call-template>
-
-  </xsl:template>
-  
-  <xsl:template match="ol|ul">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:call-template name="cr"/>
-    <xsl:apply-templates select="li">
-      <xsl:with-param name="level" select="$level"/>
-    </xsl:apply-templates>
-  </xsl:template>
-
-  <xsl:template match="ol/li">
-    <xsl:param name="level" select="'1'"/>
 
-    <xsl:variable name="item">
-      <xsl:value-of select="position()"/><xsl:text>. </xsl:text>
-      <xsl:apply-templates>
-        <xsl:with-param name="level" select="'0'"/>
-      </xsl:apply-templates>
-    </xsl:variable>
-
-    <xsl:call-template name="emit">
-      <xsl:with-param name="text" select="$item"/>
-      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
-      <xsl:with-param name="width" select="$document-width"/>
-    </xsl:call-template>
-  </xsl:template>
-  
-  <xsl:template match="ul/li">
-    <xsl:param name="level" select="'1'"/>
-
-    <xsl:variable name="item">
-      <xsl:text>* </xsl:text>
-      <xsl:apply-templates>
-        <xsl:with-param name="level" select="'0'"/>
-      </xsl:apply-templates>
-    </xsl:variable>
-
-    <xsl:call-template name="emit">
-      <xsl:with-param name="text" select="$item"/>
-      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
-      <xsl:with-param name="width" select="$document-width"/>
-    </xsl:call-template>
-
-  </xsl:template>
-  
-  <xsl:template match="dt">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:call-template name="newLine"/>
-
-    <xsl:call-template name="lineOf">
-      <xsl:with-param name="size"
-                  select="$level * $indent-per-level"/>
-    </xsl:call-template>
-    <xsl:text>: </xsl:text>
-    <xsl:apply-templates>
-      <xsl:with-param name="level" select="$level"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  
-  <xsl:template match="dd">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:call-template name="newLine"/>
-
-    <xsl:call-template name="lineOf">
-      <xsl:with-param name="size"
-                  select="$level * $indent-per-level"/>
-    </xsl:call-template>
-    <xsl:text>  </xsl:text>
-    <xsl:apply-templates>
-      <xsl:with-param name="level" select="$level"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  
   <xsl:template match="section">
     <xsl:param name="level" select="'0'"/>
 
-    <xsl:variable name="ttl">
+    <xsl:variable name="title-text">
       <xsl:value-of select="normalize-space(title)"/>
     </xsl:variable>
-    
+
     <xsl:call-template name="cr"/>
     <xsl:call-template name="lineOf">
       <xsl:with-param name="size" select="$level * $indent-per-level"/>
     </xsl:call-template>
-    <xsl:value-of select="$ttl"/>
+    <xsl:value-of select="$title-text"/>
     <xsl:call-template name="cr"/>
 
     <!-- generate a title element, level 1 -> h3, level 2 -> h4 and so on... -->
@@ -256,25 +163,25 @@
       <xsl:when test="$level=0">
         <xsl:call-template name="lineOf">
           <xsl:with-param name="chars" select="'='"/>
-          <xsl:with-param name="size" select="string-length($ttl)"/>
+          <xsl:with-param name="size" select="string-length($title-text)"/>
         </xsl:call-template>
       </xsl:when>
       <xsl:when test="$level=1">
         <xsl:call-template name="lineOf">
           <xsl:with-param name="chars" select="'-'"/>
-          <xsl:with-param name="size" select="string-length($ttl)"/>
+          <xsl:with-param name="size" select="string-length($title-text)"/>
         </xsl:call-template>
       </xsl:when>
       <xsl:when test="$level=2">
         <xsl:call-template name="lineOf">
           <xsl:with-param name="chars" select="'.-'"/>
-          <xsl:with-param name="size" select="string-length($ttl)"/>
+          <xsl:with-param name="size" select="string-length($title-text)"/>
         </xsl:call-template>
       </xsl:when>
       <xsl:when test="$level=3">
         <xsl:call-template name="lineOf">
           <xsl:with-param name="chars" select="'.'"/>
-          <xsl:with-param name="size" select="string-length($ttl)"/>
+          <xsl:with-param name="size" select="string-length($title-text)"/>
         </xsl:call-template>
       </xsl:when>
     </xsl:choose>    
@@ -286,6 +193,104 @@
     </xsl:apply-templates>
   </xsl:template>
 
+  <xsl:template match="p[@xml:space='preserve']">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:call-template name="cr"/>
+    <xsl:value-of select="."/>
+    <xsl:call-template name="cr"/>
+  </xsl:template>
+
+  <xsl:template match="source">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="."/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="''"/>
+    </xsl:call-template>
+    <xsl:call-template name="cr"/>
+  </xsl:template>
+
+  <xsl:template match="p">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:call-template name="cr"/>
+
+    <xsl:variable name="para">
+      <xsl:apply-templates>
+        <xsl:with-param name="level" select="$level"/>
+        <xsl:with-param name="width" select="$width"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="wrap-text">
+      <xsl:with-param name="text" select="$para"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="width" select="$width"/>
+    </xsl:call-template>
+
+    <xsl:call-template name="cr"/>
+
+  </xsl:template>
+
+  <xsl:template match="p" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:variable name="para">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="$level"/>
+        <xsl:with-param name="width" select="$width"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="wrap-text">
+      <xsl:with-param name="text" select="$para"/>
+      <xsl:with-param name="indent" select="'0'"/>
+      <xsl:with-param name="width" select="$width"/>
+    </xsl:call-template>
+
+    <xsl:if test="position()!=last()">
+      <xsl:call-template name="cr"/>
+    </xsl:if>
+
+  </xsl:template>
+
+  <xsl:template match="ol|ul">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+    <xsl:call-template name="cr"/>
+    <xsl:apply-templates select="li">
+      <xsl:with-param name="level" select="$level"/>
+      <xsl:with-param name="width" select="$width"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template match="ol|ul" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+    <xsl:call-template name="cr"/>
+    <xsl:apply-templates select="li" mode="in-list">
+      <xsl:with-param name="level" select="$level"/>
+      <xsl:with-param name="width" select="$width"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template match="dl">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:call-template name="cr"/>
+    <xsl:apply-templates>
+      <xsl:with-param name="level" select="$level"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template match="dl" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:apply-templates mode="in-list">
+      <xsl:with-param name="level" select="$level"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
   <xsl:template match="note | warning | fixme">
     <xsl:param name="level" select="'1'"/>
     <xsl:call-template name="cr"/>
@@ -294,7 +299,7 @@
       <xsl:with-param name="size" select="$level * $indent-per-level"/>
     </xsl:call-template>
 
-    <xsl:variable name="ttl">
+    <xsl:variable name="title-text">
       <xsl:text>** </xsl:text>
       <xsl:choose>
         <xsl:when test="@label">
@@ -308,7 +313,7 @@
     </xsl:variable>
 
     <xsl:call-template name="justify-text">
-      <xsl:with-param name="text" select="$ttl"/>
+      <xsl:with-param name="text" select="$title-text"/>
       <xsl:with-param name="width"
             select="$document-width - ($level * $indent-per-level)"/>
     </xsl:call-template>
@@ -320,12 +325,13 @@
       </xsl:apply-templates>
     </xsl:variable>
 
-    <xsl:call-template name="emit">
+    <xsl:call-template name="wrap-text">
       <xsl:with-param name="text" select="$para"/>
       <xsl:with-param name="indent" select="$level * $indent-per-level"/>
       <xsl:with-param name="width" select="$document-width"/>
     </xsl:call-template>
 
+    <xsl:call-template name="cr"/>
     <xsl:call-template name="lineOf">
       <xsl:with-param name="size" select="$level * $indent-per-level"/>
     </xsl:call-template>
@@ -339,10 +345,251 @@
 
   </xsl:template>
 
+  <xsl:template match="note | warning | fixme" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+
+    <xsl:variable name="title-text">
+      <xsl:text>** </xsl:text>
+      <xsl:choose>
+        <xsl:when test="@label">
+          <xsl:value-of select="@label"/>
+        </xsl:when>
+        <xsl:when test="local-name() = 'note'">Note</xsl:when>
+        <xsl:when test="local-name() = 'warning'">Warning</xsl:when>
+        <xsl:otherwise>Fixme (<xsl:value-of select="@author"/>)</xsl:otherwise>
+      </xsl:choose>
+      <xsl:text> **</xsl:text>
+    </xsl:variable>
+
+    <xsl:call-template name="justify-text">
+      <xsl:with-param name="text" select="$title-text"/>
+      <xsl:with-param name="width"
+            select="$document-width - ($level * $indent-per-level)"/>
+    </xsl:call-template>
+    <xsl:call-template name="cr"/>
+
+    <xsl:variable name="para">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="$level"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="wrap-text">
+      <xsl:with-param name="text" select="$para"/>
+      <xsl:with-param name="indent" select="'0'"/>
+      <xsl:with-param name="width" select="$document-width - ($level * $indent-per-level)"/>
+      <xsl:with-param name="fixed" select="true"/>
+    </xsl:call-template>
+
+    <xsl:call-template name="cr"/>
+    <xsl:call-template name="lineOf">
+      <xsl:with-param name="size"
+            select="$document-width - ($level * $indent-per-level)"/>
+      <xsl:with-param name="chars" select="'-'"/>
+    </xsl:call-template>
+    <xsl:call-template name="cr"/>
+
+  </xsl:template>
+
+  <xsl:template match="figure">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:text> </xsl:text>
+    <xsl:apply-templates>
+      <xsl:with-param name="level" select="$level"/>
+    </xsl:apply-templates>
+
+    <xsl:text>[Figure: </xsl:text>
+    <xsl:value-of select="@alt"/>
+    <xsl:text>]</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="ol/li">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:variable name="marker">
+      <xsl:value-of select="position()"/>
+      <xsl:text>. </xsl:text>
+    </xsl:variable>
+
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+        <xsl:with-param name="width" select="$width - string-length($marker)"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="$marker"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="ol/li" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:variable name="marker">
+      <xsl:value-of select="position()"/>
+      <xsl:text>. </xsl:text>
+    </xsl:variable>
+
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+        <xsl:with-param name="width" select="$width - string-length($marker)"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="$marker"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="ul/li">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+        <xsl:with-param name="width" select="$width - 2"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="'* '"/>
+    </xsl:call-template>
+
+  </xsl:template>
+
+  <xsl:template match="ul/li" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+        <xsl:with-param name="width" select="$width - 2"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="'* '"/>
+    </xsl:call-template>
+
+  </xsl:template>
+
+  <xsl:template match="dd">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="'   '"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="dd" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="'   '"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <!-- Simple items that can contain only in-line mark up -->
+  <xsl:template match="dt">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:call-template name="cr"/>
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="':: '"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="dt" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:call-template name="cr"/>
+    <xsl:variable name="item">
+      <xsl:apply-templates mode="in-list">
+        <xsl:with-param name="level" select="'0'"/>
+      </xsl:apply-templates>
+    </xsl:variable>
+    <xsl:call-template name="emit-with-indent">
+      <xsl:with-param name="text" select="$item"/>
+      <xsl:with-param name="indent" select="$level * $indent-per-level"/>
+      <xsl:with-param name="marker" select="':: '"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <!-- Handle some in-line elements that we won't actually do anything
+       with other than handle the emission of a space after the element
+       has been emitted.  Needs to be done since any text nodes will
+       have any leading spaces removed when they go through the 
+       the wrap-text() template.  This will preserve the space
+       between an in-line element and a following text node.
+  -->
+
+  <xsl:template match="em|strong|code">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:apply-templates>
+      <xsl:with-param name="level" select="$level"/>
+    </xsl:apply-templates>
+    <xsl:choose>
+      <xsl:when test="starts-with(following-sibling::text(),' ')">
+        <xsl:text> </xsl:text>
+      </xsl:when>
+      <xsl:when test="starts-with(following-sibling::text(),'&#xa;')">
+        <xsl:text> </xsl:text>
+      </xsl:when>
+      <xsl:otherwise/>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="em|strong|code" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:apply-templates>
+      <xsl:with-param name="level" select="$level"/>
+    </xsl:apply-templates>
+    <xsl:choose>
+      <xsl:when test="starts-with(following-sibling::text(),' ')">
+        <xsl:text> </xsl:text>
+      </xsl:when>
+      <xsl:when test="starts-with(following-sibling::text(),'&#xa;')">
+        <xsl:text> </xsl:text>
+      </xsl:when>
+      <xsl:otherwise/>
+    </xsl:choose>
+  </xsl:template>
+
   <xsl:template match="link|jump|fork|a">
     <xsl:param name="level" select="'1'"/>
     <xsl:apply-templates>
-      <xsl:with-param name="level" select="$level + 1"/>
+      <xsl:with-param name="level" select="$level"/>
     </xsl:apply-templates>
 
     <xsl:text>[Link to: </xsl:text>
@@ -354,7 +601,7 @@
     <xsl:param name="level" select="'1'"/>
     <xsl:text> </xsl:text>
     <xsl:apply-templates>
-      <xsl:with-param name="level" select="$level + 1"/>
+      <xsl:with-param name="level" select="$level"/>
     </xsl:apply-templates>
 
     <xsl:value-of select="concat('[Icon: ', @alt, '] ')"/>
@@ -364,7 +611,7 @@
     <xsl:param name="level" select="'1'"/>
     <xsl:text> </xsl:text>
     <xsl:apply-templates>
-      <xsl:with-param name="level" select="$level + 1"/>
+      <xsl:with-param name="level" select="$level"/>
     </xsl:apply-templates>
 
     <xsl:text>[Image: </xsl:text>
@@ -372,35 +619,6 @@
     <xsl:text>]</xsl:text>
   </xsl:template>
 
-  <xsl:template match="figure">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:text> </xsl:text>
-    <xsl:apply-templates>
-      <xsl:with-param name="level" select="$level + 1"/>
-    </xsl:apply-templates>
-
-    <xsl:text>[Figure: </xsl:text>
-    <xsl:value-of select="@alt"/>
-    <xsl:text>]</xsl:text>
-  </xsl:template>
-
-  <xsl:template match="table">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:call-template name="newLine"/>
-    <xsl:apply-templates/>
-  </xsl:template>
-    
-  <xsl:template match="tr">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:call-template name="newLine"/>
-    <xsl:apply-templates/>
-  </xsl:template>
-      
-  <xsl:template match="td">
-    <xsl:param name="level" select="'1'"/>
-    <xsl:apply-templates/>, 
-  </xsl:template>
-  
   <xsl:template match="acronym/@title">
     <xsl:param name="level" select="'1'"/>
     <xsl:attribute name="title">
@@ -425,19 +643,19 @@
       </xsl:choose>
     </span>
   </xsl:template>
-  
+
   <xsl:template match="@major">
      v<xsl:value-of select="."/>
   </xsl:template>
-  
+
   <xsl:template match="@minor">
      <xsl:value-of select="concat('.',.)"/>
   </xsl:template>
-  
+
   <xsl:template match="@fix">
      <xsl:value-of select="concat('.',.)"/>
   </xsl:template>
-  
+
   <xsl:template match="@tag">
      <xsl:value-of select="concat('-',.)"/>
   </xsl:template>
@@ -456,7 +674,29 @@
        <xsl:value-of select="@name"/>
     </a>
   </xsl:template>
-                                                                                
+
+  <xsl:template match="text()">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:call-template name="wrap-text">
+      <xsl:with-param name="text" select="."/>
+      <xsl:with-param name="indent" select="'0'"/>
+      <xsl:with-param name="width" select="$document-width - ($level * $indent-per-level)"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="text()" mode="in-list">
+    <xsl:param name="level" select="'1'"/>
+    <xsl:param name="width" select="$document-width"/>
+
+    <xsl:call-template name="wrap-text">
+      <xsl:with-param name="text" select="."/>
+      <xsl:with-param name="indent" select="'0'"/>
+      <xsl:with-param name="width" select="$width"/>
+    </xsl:call-template>
+  </xsl:template>
+
   <!--  Templates for "toc" mode.  This will generate a complete 
         Table of Contents for the document.  This will then be used
         by the site2xhtml to generate a Menu ToC and a Page ToC -->
@@ -473,7 +713,6 @@
     <xsl:param name="level" select="'1'"/>
 
     <xsl:call-template name="lineOf">
-      <xsl:with-param name="chars" select="' '"/>
       <xsl:with-param name="size" select="($level - 1) * 2"/>
     </xsl:call-template>
     <xsl:value-of select="title"/>
@@ -488,10 +727,9 @@
   <xsl:template match="text()" mode="toc">
     <xsl:value-of select="normalize-space(.)"/>
   </xsl:template>
-  
+
   <xsl:template match="node()|@*" mode="toc"/>
-    
-  
+
   <!-- End of "toc" mode templates -->
 
 </xsl:stylesheet>

Mime
View raw message