title: How to transform XML to PDF with XSLT using exponent characters in XML
body: <p>I try to print my formulas with exponents in pdf using xml, xsl and fo to transform from xml to pdf and to html. In html, i have no problem, all exponents are shown correctly. maybe because the browsers will show all utf-8 characters. but it seems that apache fop will not do that.</p>
  <p>Is there someone that can help me out, give me a tip or show me the way how to do that. i don't think that i'm the first person that needs to print exponents in pdf with fo transformations.
  the only way i managed to print exponent was to manually write inline-tags and changed the baseline-shift to &quot;move&quot; the characters higher, but i think thats not a good solution.</p>
  <p>Following example files will show my problem. In the xsl-File, i tried some things out</p>
  <p>xml-file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;demo&gt;
      &lt;formulas&gt;
        &lt;formula&gt;0,2 µm + 3 · 10⁻⁶ · a&lt;/formula&gt;
        &lt;formula&gt;0,3 µm + 4 · 10⁻³ · b&lt;/formula&gt;
        &lt;formula&gt;0,4 µm + 5 · E-6 · c&lt;/formula&gt;
        &lt;formula&gt;0,5 µm + 6 · E-3 · d&lt;/formula&gt;
      &lt;/formulas&gt;
  &lt;/demo&gt;
  </code></pre>
  <p>xsl-file with some tries:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xsl:stylesheet version=&quot;2.0&quot;
      xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
      xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
      xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;
      xmlns:own=&quot;http://www.own.com&quot;
      &gt;
  
      &lt;xsl:template match=&quot;/demo&quot;&gt;
          &lt;fo:root xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;&gt;
              &lt;fo:layout-master-set&gt;
                  &lt;fo:simple-page-master master-name=&quot;master_demo&quot; page-width=&quot;21.0cm&quot; page-height=&quot;29.7cm&quot; margin-top=&quot;0.5cm&quot; margin-bottom=&quot;0.25cm&quot; margin-left=&quot;2.0cm&quot; margin-right=&quot;1.0cm&quot;&gt;
                      &lt;fo:region-body region-name=&quot;flow_demo&quot; margin-top=&quot;0.0cm&quot; margin-bottom=&quot;0.85cm&quot; /&gt;
                      &lt;fo:region-before extent=&quot;4.5cm&quot; /&gt;
                      &lt;fo:region-after extent=&quot;0.5cm&quot;/&gt;
                  &lt;/fo:simple-page-master&gt;
              &lt;/fo:layout-master-set&gt;
  
              &lt;fo:page-sequence master-reference=&quot;master_demo&quot;&gt;
                  &lt;fo:flow flow-name=&quot;flow_demo&quot;&gt;
                      &lt;fo:block-container absolute-position=&quot;fixed&quot; top=&quot;5.0cm&quot; margin-left=&quot;1.0cm&quot;&gt;
                          &lt;fo:block&gt;
                              &lt;fo:table&gt;
                                  &lt;fo:table-column column-width=&quot;6.0cm&quot;/&gt;
                                  &lt;fo:table-column column-width=&quot;6.0cm&quot;/&gt;
                                  &lt;fo:table-column column-width=&quot;6.0cm&quot;/&gt;
                                  &lt;fo:table-body&gt;
                                      &lt;xsl:for-each select=&quot;formulas/formula&quot;&gt;
                                          &lt;fo:table-row&gt;
                                              &lt;fo:table-cell&gt;
                                                  &lt;fo:block font-size=&quot;9pt&quot; font-family=&quot;SansSerif&quot; margin-top=&quot;0.2cm&quot;&gt;
                                                      Test:&amp;#160;&lt;xsl:value-of select=&quot;own:GetFormattedFormulaPDF(.)&quot;/&gt;
                                                  &lt;/fo:block&gt;
                                              &lt;/fo:table-cell&gt;
                                              &lt;fo:table-cell&gt;
                                                  &lt;fo:block font-size=&quot;9pt&quot; font-family=&quot;SansSerif&quot; margin-top=&quot;0.2cm&quot;&gt;
                                                      Test:&amp;#160;&lt;xsl:copy-of select=&quot;own:GetFormattedFormulaPDF(.)&quot;&gt;&lt;/xsl:copy-of&gt;
                                                  &lt;/fo:block&gt;
                                              &lt;/fo:table-cell&gt;
                                              &lt;fo:table-cell&gt;
                                                  &lt;fo:block font-size=&quot;9pt&quot; font-family=&quot;SansSerif&quot; margin-top=&quot;0.2cm&quot;&gt;
                                                      Test:&amp;#160;&amp;#8254;&amp;#179;&amp;#8254;&amp;#179;&amp;#8315;
                                                  &lt;/fo:block&gt;
                                              &lt;/fo:table-cell&gt;
                                          &lt;/fo:table-row&gt;
                                      &lt;/xsl:for-each&gt;
                                  &lt;/fo:table-body&gt;
                              &lt;/fo:table&gt;
  
                              &lt;fo:table margin-top=&quot;2.0cm&quot;&gt;
                                  &lt;fo:table-column column-width=&quot;10.0cm&quot;/&gt;
                                  &lt;fo:table-body&gt;
                                      &lt;xsl:for-each select=&quot;formulas/formula&quot;&gt;
                                          &lt;fo:table-row&gt;
                                              &lt;fo:table-cell&gt;
                                                  &lt;fo:block font-size=&quot;9pt&quot; font-family=&quot;SansSerif&quot; margin-top=&quot;0.2cm&quot;&gt;
                                                      XML-Text:&amp;#160;&lt;xsl:value-of select=&quot;.&quot;/&gt;
                                                  &lt;/fo:block&gt;
                                              &lt;/fo:table-cell&gt;
                                          &lt;/fo:table-row&gt;
                                      &lt;/xsl:for-each&gt;
                                  &lt;/fo:table-body&gt;
                              &lt;/fo:table&gt;
  
                              &lt;fo:table margin-top=&quot;2.0cm&quot;&gt;
                                  &lt;fo:table-column column-width=&quot;10.0cm&quot;/&gt;
                                  &lt;fo:table-body&gt;
                                      &lt;xsl:for-each select=&quot;formulas/formula&quot;&gt;
                                          &lt;fo:table-row&gt;
                                              &lt;fo:table-cell&gt;
                                                  &lt;fo:block font-size=&quot;9pt&quot; font-family=&quot;SansSerif&quot; margin-top=&quot;0.2cm&quot;&gt;
                                                      &lt;xsl:call-template name=&quot;mu&quot;&gt;
                                                          &lt;xsl:with-param name=&quot;formula&quot; select = &quot;.&quot; /&gt;
                                                      &lt;/xsl:call-template&gt;
                                                  &lt;/fo:block&gt;
                                              &lt;/fo:table-cell&gt;
                                          &lt;/fo:table-row&gt;
                                      &lt;/xsl:for-each&gt;
                                  &lt;/fo:table-body&gt;
                              &lt;/fo:table&gt;
  
                              &lt;fo:table margin-top=&quot;2.0cm&quot;&gt;
                                  &lt;fo:table-column column-width=&quot;10.0cm&quot;/&gt;
                                  &lt;fo:table-body&gt;
                                      &lt;xsl:for-each select=&quot;formulas/formula&quot;&gt;
                                          &lt;fo:table-row&gt;
                                              &lt;fo:table-cell&gt;
                                                  &lt;fo:block font-size=&quot;9pt&quot; font-family=&quot;SansSerif&quot; margin-top=&quot;0.2cm&quot;&gt;
                                                      Formula with fo-tags:&amp;#160;0,9 µm + 5 · 10&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–4&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;abc&lt;/fo:inline&gt;
                                                  &lt;/fo:block&gt;
                                              &lt;/fo:table-cell&gt;
                                          &lt;/fo:table-row&gt;
                                      &lt;/xsl:for-each&gt;
                                  &lt;/fo:table-body&gt;
                              &lt;/fo:table&gt;
  
                          &lt;/fo:block&gt;
                      &lt;/fo:block-container&gt;
                  &lt;/fo:flow&gt;
              &lt;/fo:page-sequence&gt;
  
          &lt;/fo:root&gt;
      &lt;/xsl:template&gt;
      
      &lt;xsl:function name=&quot;own:GetFormattedFormulaPDF&quot; as=&quot;xs:string&quot;&gt;
          &lt;xsl:param name=&quot;mu&quot; as=&quot;xs:string&quot;&gt;&lt;/xsl:param&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test=&quot;contains($mu, '10⁻³')&quot;&gt;
                  &lt;xsl:variable name=&quot;E-3d&quot;&gt;
                      10&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–3&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;d&lt;/fo:inline&gt;
                  &lt;/xsl:variable&gt;
                  &lt;xsl:value-of select=&quot;concat(substring-before($mu, '10⁻³'),$E-3d)&quot;/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test=&quot;contains($mu, '10⁻⁶')&quot;&gt;
                  &lt;xsl:variable name=&quot;E-6d&quot;&gt;
                      10&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–6&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;d&lt;/fo:inline&gt;
                  &lt;/xsl:variable&gt;
                  &lt;xsl:value-of select=&quot;concat(substring-before($mu, '10⁻⁶'),$E-6d)&quot;/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:variable name=&quot;formel&quot;&gt;
                      Formel direkt -&gt; 50&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–12&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;dx&lt;/fo:inline&gt;
                  &lt;/xsl:variable&gt;
                  &lt;xsl:value-of select=&quot;$formel&quot;/&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:function&gt;
      
      &lt;xsl:template name=&quot;mu&quot;&gt;
          &lt;xsl:param name=&quot;formula&quot;&gt;&lt;/xsl:param&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test=&quot;contains($formula, '10⁻³')&quot;&gt;
                  &lt;xsl:variable name=&quot;E-3d&quot;&gt;
                      Hier Minus 3 -&gt; 10&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–3&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;d&lt;/fo:inline&gt;
                  &lt;/xsl:variable&gt;
                  &lt;xsl:value-of select=&quot;concat(substring-before($formula, '10⁻³'),$E-3d)&quot;/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test=&quot;contains($formula, '10⁻⁶')&quot;&gt;
                  &lt;xsl:variable name=&quot;E-6d&quot;&gt;
                      Hier Minus 6 -&gt; 10&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–6&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;d&lt;/fo:inline&gt;
                  &lt;/xsl:variable&gt;
                  &lt;xsl:value-of select=&quot;concat(substring-before($formula, '10⁻⁶'),$E-6d)&quot;/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:variable name=&quot;formel&quot;&gt;
                      Formel direkt -&gt; 50&lt;fo:inline font-size=&quot;7pt&quot; baseline-shift=&quot;40%&quot;&gt;–12&lt;/fo:inline&gt; · &lt;fo:inline font-style=&quot;italic&quot;&gt;dx&lt;/fo:inline&gt;
                  &lt;/xsl:variable&gt;
                  &lt;xsl:value-of select=&quot;$formel&quot;/&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;        
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>