title: How can I suppress identical footnotes with XSLT/XSL-FO?
body: <p>First of all, I'm trying to create a PDF from an XML with help of XSLT, XPath and XSL-FO.</p>
  
  <p>I have an XML with multiple footnotes and I use a template to render them automatically after tag name "note".</p>
  
  <p><strong>XML:</strong></p>
  
  <pre><code>&lt;document&gt;  
    &lt;ul type='custom-list-1' startdist="0.5cm" gap="0.15cm"&gt;
      &lt;li space-before="30pt"&gt;
          List-item 1
          &lt;block margin-left="-15pt" margin-right="-15pt" text-align="center"&gt;
              &lt;table layout="fixed" width="100%"&gt;
                  &lt;col number="1" width="30%" /&gt;
                  &lt;col number="2" width="17%" /&gt;
                  &lt;col number="3" width="17%" /&gt;
                  &lt;col number="4" width="17%" /&gt;
                  &lt;col number="5" width="17%" /&gt;                      
                  &lt;tbody&gt;
                      &lt;tr font-style="italic"&gt;
                          &lt;th&gt;sample title&lt;/th&gt;
                          &lt;th colspan="4"&gt;sample title&lt;/th&gt;
                      &lt;/tr&gt;                       
                      &lt;tr&gt;
                          &lt;td&gt;
                              Bla bla bla
                              &lt;note name="name-1"&gt;
                                  Footnote for "bla bla bla"
                              &lt;/note&gt;
                          &lt;/td&gt;
                          &lt;td colspan="4"&gt;
                              .............
                          &lt;/td&gt;
                      &lt;/tr&gt;                   
                      &lt;tr&gt;
                          &lt;td&gt;
                              Comision Administrare Online Banking
                          &lt;/td&gt;
                          &lt;td colspan="4"&gt;
                              .........
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              Another... Bla bla bla
                              &lt;note name="name-2"&gt;
                                  Footnote for "Another... Bbla bla bla"
                              &lt;/note&gt;
                          &lt;/td&gt;
                          &lt;td colspan="4"&gt;
                              ......
                          &lt;/td&gt;
                      &lt;/tr&gt;                       
                  &lt;/tbody&gt;                
              &lt;/table&gt;                            
          &lt;/block&gt;
      &lt;/li&gt;
      &lt;li space-before="30pt"&gt;List-item 2:        
  
          &lt;block margin-left="-15pt" text-align="center"&gt;
              &lt;table layout="fixed" width="100%"&gt;
                  &lt;col number="1" width="18%" /&gt;
                  &lt;col number="2" width="13%" /&gt;
                  &lt;col number="3" width="13%" /&gt;
                  &lt;col number="4" width="16%" /&gt;                  
                  &lt;col number="5" width="13%" /&gt;
                  &lt;col number="6" width="13%" /&gt;
                  &lt;col number="7" width="13%" /&gt;
                  &lt;tbody&gt;
                      &lt;tr font-style="italic"&gt;
                          &lt;th colspan="2" rowspan="2"&gt;Sample title&lt;/th&gt;
                          &lt;th colspan="2"&gt;Sample title&lt;/th&gt;                       
                          &lt;th rowspan="2"&gt;Sample title&lt;/th&gt;
                          &lt;th rowspan="2"&gt;Sample title&lt;/th&gt;
                          &lt;th rowspan="2"&gt;Sample title&lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;tr font-style="italic"&gt;
                          &lt;th&gt;Min&lt;/th&gt;
                          &lt;th&gt;Max&lt;/th&gt;
                      &lt;/tr&gt;                       
                      &lt;tr&gt;                            
                          &lt;td colspan="2"&gt;Some text here&lt;/td&gt;
                          &lt;td colspan="2"&gt;
                              1%
                              &lt;note name="name-3"&gt;
                                  Footnote for "1%"
                              &lt;/note&gt;
                              / 0.5%
                              &lt;note name="name-4"&gt;
                                  Footnote for "0.5%"
                              &lt;/note&gt;
                          &lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;                          
                      &lt;/tr&gt;                       
                      &lt;tr&gt;                            
                          &lt;td colspan="2"&gt;Sample text&lt;/td&gt;
                          &lt;td colspan="2"&gt;
                              1%
                              &lt;note name="name-3"&gt;
                                  Footnote for "1%"
                              &lt;/note&gt;
                              / 0.5%
                              &lt;note name="name-4"&gt;
                                  Footnote for "0.5%"
                              &lt;/note&gt;
                          &lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;                          
                      &lt;/tr&gt;                       
                      &lt;tr&gt;                            
                          &lt;td colspan="2"&gt;Sample text&lt;/td&gt;
                          &lt;td colspan="2"&gt;
                              1%
                              &lt;note name="name-3"&gt;
                                  Footnote for "1%"
                              &lt;/note&gt;
                              / 0.5%
                              &lt;note name="name-4"&gt;
                                  Footnote for "0.5%"
                              &lt;/note&gt;
                          &lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;
                          &lt;td&gt;-&lt;/td&gt;                          
                      &lt;/tr&gt;                       
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/block&gt;
      &lt;/li&gt;
      &lt;li space-before="30pt"&gt;List-item 3
          &lt;block margin-left="-15pt" text-align="center"&gt;
              &lt;table layout="fixed" width="100%"&gt;
                  &lt;col number="1" width="25%" /&gt;
                  &lt;col number="2" width="15%" /&gt;
                  &lt;col number="3" width="15%" /&gt;
                  &lt;col number="4" width="22%" /&gt;
                  &lt;col number="5" width="22%" /&gt;                      
                  &lt;tbody&gt;
                      &lt;tr font-style="italic"&gt;
                          &lt;th colspan="2"&gt;Sample title&lt;/th&gt;
                          &lt;th&gt;&lt;/th&gt;
                          &lt;th&gt;Sample title&lt;/th&gt;
                          &lt;th&gt;Sample title&lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;                            
                          &lt;td colspan="2"&gt;Sample text&lt;/td&gt;                            
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;0%&lt;/td&gt;
                          &lt;td&gt;0%&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;                            
                          &lt;td colspan="2"&gt;Sample text&lt;/td&gt;                            
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;0.05%&lt;note name="name-5"&gt;Footnote for "0.05%"&lt;/note&gt;&lt;/td&gt;
                          &lt;td&gt;0.05%&lt;/td&gt;
                      &lt;/tr&gt;                       
                      &lt;tr&gt;                            
                          &lt;td colspan="2"&gt;Sample text&lt;/td&gt;                            
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;0%&lt;/td&gt;
                          &lt;td&gt;0%&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
  
          &lt;/block&gt;
      &lt;/li&gt;       
  &lt;/ul&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>XSLT:</strong></p>
  
  <pre><code>&lt;xsl:attribute-set name="note.data" &gt;
      &lt;xsl:attribute name="text-align"&gt;justify&lt;/xsl:attribute&gt;        
      &lt;xsl:attribute name="font-weight"&gt;normal&lt;/xsl:attribute&gt;
  &lt;/xsl:attribute-set&gt;
  
  &lt;xsl:key name="by-name" match="//note[@name]" use="@name" /&gt;
  
  &lt;xsl:template match="note"&gt;
      &lt;xsl:call-template name="note" /&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="note"&gt;
      &lt;xsl:param name="unique-elements" 
         select="current()[generate-id(.) = generate-id(key('by-name', @name)[1])]"/&gt;     
      &lt;xsl:param name="identical-elements" 
         select="current()[not(generate-id(.) = generate-id(key('by-name', @name)[1]))]"/&gt;
  
      &lt;xsl:if test="$unique-elements"&gt;
          &lt;xsl:variable name="element" select="$unique-elements"/&gt;
  
          &lt;fo:footnote&gt;       
              &lt;fo:inline baseline-shift="super" font-size="75%" color="red"&gt;
                  &lt;xsl:number level="any" count="//note[generate-id(.) = generate-id(key('by-name', @name)[1])]" format="(1)" /&gt;
              &lt;/fo:inline&gt;
  
              &lt;fo:footnote-body xsl:use-attribute-sets="note.data"&gt;   
                  &lt;fo:block color="blue"&gt;                             
                      &lt;fo:inline baseline-shift="super" font-size="75%"&gt;
                          &lt;xsl:number level="any" count="//note[generate-id(.) = generate-id(key('by-name', @name)[1])]" format="(1)" /&gt;
                      &lt;/fo:inline&gt;
                      &lt;xsl:value-of select="$element" /&gt;                                              
                  &lt;/fo:block&gt;
              &lt;/fo:footnote-body&gt;
          &lt;/fo:footnote&gt;          
      &lt;/xsl:if&gt;           
  
      &lt;xsl:if test="$identical-elements"&gt;
          &lt;fo:inline baseline-shift="super" font-size="75%" color="green"&gt;
              &lt;xsl:number level="any" count="//note[generate-id(.) = generate-id(key('by-name', @name)[1])]" format="(1)" /&gt;
          &lt;/fo:inline&gt;            
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p><strong>PDF output:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/yhNvu.png" alt="enter image description here"></p>
  
  <p>So, I managed to suppress the identical footnotes and maintain the count of the unique footnotes (in image colored with red) and add the last count value for the identical footnotes (in image colored with green).</p>
  
  <p>The problem now is that I can't figure it out how can I maintain the same count value for the identical footnotes.</p>
  
  <p>Thanks in advance!</p>