title: Count Figure number by chapter level with XSL in Dita OT plugin
body: <p>In default DITA OT pdf plug in,  all figures are numbered by document level, which  is from figure 1 ,2, 3 to the last figure of this document.</p>
  
  <p>I wish to have figure numbered by chapter level</p>
  
  <pre><code>In chapter 1, I have figure 1-1, 1-2, .....
  In chapter 2, I have figure 2-1, 2-2, etc.
  </code></pre>
  
  <p>Each chapter can have sub chapters and each chapter xml format is like below, no matter it is chapter 1 or chapter 1.1.1.</p>
  
  <pre><code> &lt;topic id="concept_hvx_wyx_dk"&gt;
      &lt;title&gt;Toolbar&lt;/title&gt;` 
          &lt;conbody&gt;
           &lt;p&gt;This section describes the usage of the toolbar.
            &lt;fig&gt;
           &lt;image placement="break" href="../images/toolbar.png" id="image_gw5_dtx_dk" width="450"/&gt;
  &lt;/fig&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>The code I used to count figure number by the document leve is below and it works OK.</p>
  
  <pre><code>    &lt;xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" mode="table.title-number"&gt;
      &lt;xsl:call-template name="getChapterPrefix" /&gt;
      &lt;xsl:value-of select="count(key('enumerableByClass', 'topic/table', ancestor::*[contains(@class, ' topic/topic ')][last()])[. &amp;lt;&amp;lt; current()])" /&gt;
    &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The code I copied to count figure number by chapter lever is below and it works NOK. All figures are still numbered from 1, 2 ... in document level.</p>
  
  <p>Can anyone check it for me or explain it, since I am a new hand for this xsl. </p>
  
  <pre><code>   &lt;xsl:template match="*[contains(@class, ' topic/fig ')]/*[contains(@class, ' topic/title ')]" mode="fig.title-number"&gt;
      &lt;xsl:call-template name="getChapterPrefix" /&gt;    
        &lt;xsl:value-of select="count(key('enumerableByClass', 'topic/fig', ancestor::*[contains(@class, ' topic/topic ')][last()])&amp;#xA;  *[contains(@class, ' topic/title ')]]&amp;#xA; [. &amp;lt;&amp;lt; current()])" /&gt;
    &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Thanks a lot!</p>
  
  <p>Lisa</p>