Formatting an XML Document

Writing an entire document using the XSL formatting objects is not an easy task except for short documents. I have a hard time imagining anyone using the formatting objects to write a book, for example. W3C foresaw that difficulty, and that's one of the main reasons that it also introduced the transformation language we took a look at in the previous chapter. You can write a document using your own tags, and you can use XSLT to transform the document so that it uses the XSL formatting objects. In practice, that's almost invariably the way it's done, which means that all you have to supply is an XSLT style sheet that can be used to convert your document to use formatting objects. In this way, an XSLT processor can do all the work for you, transforming a document from a form you're comfortable working with to formatting an object form, which you can then feed to a program that can handle formatting objects and display the formatted result.

To make all this self-evident, I'll write an example here using the planets.xml document we saw in the previous chapter:

<?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 chapter, I'll write an XSLT style sheet for this document, transforming it so that it uses formatting objects. Then I'll use the FOP processor to turn the new document into a PDF file. I'll also take a look at the formatted document with Adobe Acrobat.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.207.174