title: How to show correctly tabulation in xsl-fo?
body: <p>I have an XML document and I am creating an XSL-FO file to convert it to pdf with apache-fop.</p>
  
  <p>In the xml, there are sections &lt;code> to show... code.</p>
  
  <p>In the xsl-fo, I added the white-space="pre" sentence to preserve the code format, but tabulations are shown like single space:</p>
  
  <p>XML section:</p>
  
  <pre><code>&lt;code&gt;&lt;![CDATA[
  function callback( widget )
  {
      var ui = widget; // It should be a tab
  }
  ]]&gt;&lt;/code&gt;
  </code></pre>
  
  <p>XSL-FO section:</p>
  
  <pre><code>&lt;xsl:template match="code"&gt;
      &lt;fo:block font-size="10pt" font-family="monospace" white-space="pre" color="#008000" background-color="#f8f8f8"&gt;
          &lt;xsl:apply-templates/&gt;
      &lt;/fo:block&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Resulting PDF:</p>
  
  <pre><code>function callback( widget )
  {
   var ui = widget;  // It should be a tab
  }
  </code></pre>
  
  <p>So my question is: <strong>How to preserve or set the size of the tabulation?</strong></p>
  
  <hr>
  
  <p>Edited: I am using apache-fop 1.1</p>
  
  <p>A full example:</p>
  
  <p>proyecto.xml (do not forget to replace the 4 spaces by a tab before "var ui...")</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="proyecto.xsl"?&gt;
  &lt;document&gt;
  &lt;code&gt;&lt;![CDATA[
  function callback( widget )
  {
      var ui = widget; // It should be a tab
  }
  ]]&gt;&lt;/code&gt;
  &lt;/document&gt;
  </code></pre>
  
  <p>proyecto.xsl</p>
  
  <pre><code>&lt;xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
  
      &lt;xsl:template match ="document"&gt;
          &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
              &lt;fo:layout-master-set&gt;
                  &lt;fo:simple-page-master master-name="OnePage" margin="1in" 
                      page-height="29.7cm" 
                      page-width="21cm"
                      margin-top="2.5cm"
                      margin-bottom="2.5cm"
                      margin-left="3.5cm"
                      margin-right="2.5cm"&gt;
                      &lt;fo:region-body margin="0cm"/&gt;
                  &lt;/fo:simple-page-master&gt;
                  &lt;fo:page-sequence-master master-name="Page"&gt;
                      &lt;fo:single-page-master-reference master-reference="OnePage"/&gt;
                  &lt;/fo:page-sequence-master&gt;
              &lt;/fo:layout-master-set&gt;
  
              &lt;fo:page-sequence master-reference="Page"&gt;
                  &lt;fo:flow flow-name="xsl-region-body"&gt;
                      &lt;xsl:apply-templates/&gt;
                  &lt;/fo:flow&gt;
              &lt;/fo:page-sequence&gt;
          &lt;/fo:root&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="code"&gt;
          &lt;fo:block font-size="10pt" font-family="monospace" white-space="pre"&gt;
              &lt;xsl:apply-templates/&gt;
              &lt;!--&lt;xsl:value-of select="replace( . , 'a', 'b')"/&gt;--&gt;
          &lt;/fo:block&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>PDF result (screen):</p>
  
  <p><img src="https://i.stack.imgur.com/6nAkS.png" alt="enter image description here"></p>