Adding 'List First' and 'List Last' Paragraph Styles

Description

I wanted greater control over my list items. I wanted to control space above/below and the keep-with-next/previous options, but I wanted different settings for my first list item, my in between list items, and my last item. By default in ePublisher, you only get one list item paragraph style. By editing default.wwconfig, you can get more.

List First/Last/Middle

I modified the Style match that creates the Choice, Unordered Step, and List paragraph styles. I added <xsl:when> to test for preceding and following siblings. Based on the results of those checks, new styles are created for Choice First, Choice Last, and Choice Middle. The same goes for Unordered Step and Lists.

 <Style match="//*[contains(@class, ' topic/ul ')]/*[contains(@class, ' topic/li ')] | //*[contains(@class, ' topic/ul ')]/*[contains(@class, ' topic/li ')]/*[1][(contains(@class, ' topic/p ')) and (normalize-space(preceding-sibling::text()) = '')]">
   <xsl:variable name="VarIndent" select="18" />
   <xsl:variable name="VarLevel" select="count(ancestor::*[contains(@class, ' topic/ol ') or contains(@class, ' topic/sl ') or contains(@class, ' topic/ul ') or contains(@class, ' topic/dl ')]) - count(ancestor::*[contains(@class, ' topic/table ') or contains(@class, ' topic/simpletable ')][1]/ancestor::*[contains(@class, ' topic/ol ') or contains(@class, ' topic/sl ') or contains(@class, ' topic/ul ') or contains(@class, ' topic/dl ')])" />

   <xsl:variable name="VarName">
    <xsl:choose>
     
     <xsl:when test="string-length(@outputclass) &gt; 0">
      <xsl:value-of select="@outputclass" />
     </xsl:when>
     
     <!-- Customized by adding the preceding sibling count and text/name. -->
     <!-- -Lief 1.Oct.2013 -->
     <xsl:when test="contains(@class, ' task/choice ') and count(preceding-sibling::*)=0">
      <xsl:text>Choice First</xsl:text>
     </xsl:when>
     
     <!-- Customized by adding the following sibling count and text/name. -->
     <!-- -Lief 1.Oct.2013 -->     
     <xsl:when test="contains(@class, ' task/choice ') and count(following-sibling::*)=0">
      <xsl:text>Choice Last</xsl:text>
     </xsl:when>

     <!-- Customized by adding the preceding sibling and following sibling count and text/name. -->
     <!-- -Lief 1.Oct.2013 -->
     <xsl:when test="contains(@class, ' task/choice ') and count(following-sibling::*)&gt;0 and count(preceding-sibling::*)&gt;0">
      <xsl:text>Choice Middle</xsl:text>
     </xsl:when>
     
     <xsl:when test="contains(@class, ' task/step ') and count(preceding-sibling::*)=0">
      <xsl:text>Unordered Step First</xsl:text>
     </xsl:when>
     
     <xsl:when test="contains(@class, ' task/step ') and count(following-sibling::*)=0">
      <xsl:text>Unordered Step Last</xsl:text>
     </xsl:when>
     
     <xsl:when test="contains(@class, ' task/step ') and count(following-sibling::*)&gt;0 and count(preceding-sibling::*)&gt;0">
      <xsl:text>Unordered Step Middle</xsl:text>
     </xsl:when>

     <xsl:when test="contains(@class, ' topic/li ') and count(preceding-sibling::*)=0">
      <xsl:text>List First</xsl:text>
     </xsl:when>
     
     <xsl:when test="contains(@class, ' topic/li ') and count(following-sibling::*)=0">
      <xsl:text>List Last</xsl:text>
     </xsl:when>
     
     <xsl:when test="contains(@class, ' topic/li ') and count(following-sibling::*)&gt;0 and count(preceding-sibling::*)&gt;0">
      <xsl:text>List Middle</xsl:text>
     </xsl:when>
     
     <!-- If it gets this far and uses the otherwise option, something is wrong with the logic above. -->
     <!-- -Lief 1.Oct.2013 -->
     <xsl:otherwise>
      <xsl:text>List FAIL</xsl:text>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:variable>

   <wwditaconfig:Head name="{$VarName} {$VarLevel}">
    <wwdoc:Style>
     <wwdoc:Attribute name="font-family" value="Calibri" />
     <wwdoc:Attribute name="font-size" value="12pt" />
     <wwdoc:Attribute name="margin-left" value="{$VarLevel * $VarIndent}pt" />
     <wwdoc:Attribute name="margin-top" value="6pt" />
     <wwdoc:Attribute name="margin-bottom" value="6pt" />
     <wwdoc:Attribute name="text-indent" value="-{$VarIndent}pt" />
    </wwdoc:Style>

    <xsl:variable name="VarValue">
     <xsl:number level="single" format="1" count="*[contains(@class, ' topic/li ')]" />
    </xsl:variable>

    <xsl:variable name="VarBullet">
     <xsl:choose>
      <xsl:when test="$VarLevel = 1">
       <xsl:text>&#8226;</xsl:text>
      </xsl:when>

      <xsl:when test="$VarLevel = 2">
       <xsl:text>&#9702;</xsl:text>
      </xsl:when>

      <xsl:otherwise>
       <xsl:text>&#9642;</xsl:text>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:variable>

    <wwdoc:Number value="{$VarValue}">
     <wwdoc:Style>
      <wwdoc:Attribute name="list-style-type" value="bullet" />
      <wwdoc:Attribute name="wwdoc-list-level" value="{$VarLevel}" />
     </wwdoc:Style>

     <wwdoc:Text value="{$VarBullet} " />
    </wwdoc:Number>
   </wwditaconfig:Head>

   <wwditaconfig:Remainder name="{$VarName} {$VarLevel} Continued">
    <wwdoc:Style>
     <wwdoc:Attribute name="margin-left" value="{$VarLevel * $VarIndent}pt" />
    </wwdoc:Style>
   </wwditaconfig:Remainder>
  </Style>

Step and Numbered

Find and repeat the above process for Step and Numbered, too, although you'll need to correctly test for the class ' task/step ' and ' topic/li ' respectively. Depending on the complexity of your files, you could end up with a lot of new paragraph styles, but the assumption is that you are fine with that because you want more control. In my case I have 52 new styles that replaced 13 old ones.


CategoryHowto

HelpCenter/Tips/DITA: List First and List Last (last edited 2013-10-01 21:28:36 by LiefErickson)