Formatting an XML Document

Formatting an XML Document

To see how XSL-FO can format XML data, Ill use planets.xml:

Listing 11.1 planets.xml
 <?xml version="1.0"?>  <?xml-stylesheet type="text/xml" href="planets.xsl"?>  <PLANETS>    <PLANET COLOR="RED">      <NAME>Mercury</NAME>      <MASS UNITS="(Earth = 1)">.0553</MASS>      <DAY UNITS="days">58.65</DAY>      <RADIUS UNITS="miles">1516</RADIUS>      <DENSITY UNITS="(Earth = 1)">.983</DENSITY>      <DISTANCE UNITS="million miles">43.4</DISTANCE><!--At perihelion-->    </PLANET>    <PLANET COLOR="WHITE">      <NAME>Venus</NAME>      <MASS UNITS="(Earth = 1)">.815</MASS>      <DAY UNITS="days">116.75</DAY>      <RADIUS UNITS="miles">3716</RADIUS>      <DENSITY UNITS="(Earth = 1)">.943</DENSITY>      <DISTANCE UNITS="million miles">66.8</DISTANCE><!--At perihelion-->    </PLANET>    <PLANET COLOR="BLUE">      <NAME>Earth</NAME>      <MASS UNITS="(Earth = 1)">1</MASS>      <DAY UNITS="days">1</DAY>      <RADIUS UNITS="miles">2107</RADIUS>      <DENSITY UNITS="(Earth = 1)">1</DENSITY>      <DISTANCE UNITS="million miles">128.4</DISTANCE><!--At perihelion-->    </PLANET>  </PLANETS> 

In this first example, I create an XSLT stylesheet to format planets.xml into planets.fo, which uses formatting objects to specify fonts, styles, and colors. Then I use the fop processor to convert planets.fo into planets.pdf, which you can see in Figure 11.1.

Figure 11.1. A PDF document created with formatting objects.
graphics/11fig01.gif

As you see in Figure 11.1, I use some text formatting in this first example: setting the font, underlining text, italicizing text, even setting text color. (Although you cant see it in Figure 11.1, the title, The Planets Table, is bright blue.)

The first step in creating Figure 11.1 is to use an XSLT stylesheet to transform planets.xml to planets.fo.



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net