web analytics

Subscripts and Superscripts in the XSLT

Options

codeling 1602 - 6666
@2019-06-24 13:31:38

The following xslt script shows how to use <fo:inline> elements to create subscripts of superscripts in the output.

The property that controls the alignment of an inline element vertically within it's parent line is baseline-shift. As it is illustrated in this example, the text can be shifted vertically using either "sub" or "super" which will use font metrics to determine the subscript or superscript positions. Also a percentual or absolute value can be used.

 

 

<?xml version="1.0" encoding="utf-8" ?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

       <fo:layout-master-set>

               <fo:simple-page-master master-name="LetterPage" page-width="5in" page-height="1.6in">

                       <fo:region-body region-name="PageBody" margin="0.2in"/>

               </fo:simple-page-master>

       </fo:layout-master-set>

       <fo:page-sequence master-reference="LetterPage">

               <fo:flow flow-name="PageBody" font="10pt Arial">

                       <fo:block>

                       Normal text

                       <fo:inline baseline-shift="sub" background="rgb(66,165,255)">sub-script</fo:inline>

                       normal text

                       <fo:inline baseline-shift="super" background="rgb(66,165,255)">super-script</fo:inline>

                       normal text.

               </fo:block>

                       <fo:block>

                       Normal text

                       <fo:inline baseline-shift="-50%" background="rgb(66,165,255)">-50%</fo:inline>

                       normal text

                       <fo:inline baseline-shift="50%" background="rgb(66,165,255)">+50%</fo:inline>

                       normal text.

               </fo:block>

                       <fo:block>

                       Normal text

                       <fo:inline baseline-shift="-5pt" background="rgb(66,165,255)">-5pt</fo:inline>

                       normal text

                       <fo:inline baseline-shift="5pt" background="rgb(66,165,255)">5pt</fo:inline>

                       normal text.

               </fo:block>

               </fo:flow>

       </fo:page-sequence>

</fo:root>

 

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com