Transforming a Document into Formatting Object Form

Transforming a Document into Formatting Object Form

To transform planets.xml into a document that uses formatting objects, which Ill call planets.fo, all I have to do is apply the stylesheet planetsPDF.xsl. You can do that using the XSLT techniques you already saw in this chapter.

For example, to use Xalan to create planets.fo, you first set the classpath something like this in Windows:

 C:\>set classpath=c:\xalan\xalan-j_2_0_0\bin\xalan.jar;  c:\xalan\xalan-j_2_0_0\bin\xerces.jar 

Then you apply planetsPDF.xsl to planets.xml to produce planets.fo:

 C:\planets>java org.apache.xalan.xslt.Process -IN planets.xml -XSL planetsPDF.xsl -OUT graphics/ccc.gif planets.fo 

The document planets.fo uses the XSL formatting objects to specify how the document should be formatted. Heres what planets.fo looks like:

Listing 1.9 planets.fo
 <?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 margin-right="20mm" margin-left="20mm"          margin-bottom="10mm" margin-top="10mm"          page-width="300mm" page-height="400mm" master-name="page">  <fo:region-body margin-right="0mm" margin-left="0mm"              margin-bottom="10mm" margin-top="0mm"/>          <fo:region-after extent="10mm"/>      </fo:simple-page-master>  </fo:layout-master-set>  <fo:page-sequence master-name="page">      <fo:flow flow-name="xsl-region-body">  <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt" font-weight="bold">              Name:              Mercury          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Mass (Earth = 1):              .0553          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Day (Earth = 1):              58.65          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Radius (in miles):              1516          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Density (Earth = 1):              .983          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Distance (million miles):              43.4          </fo:block>  <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt" font-weight="bold">              Name:              Venus          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Mass (Earth = 1):              .815          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Day (Earth = 1):              116.75          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Radius (in miles):              3716          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Density (Earth = 1):              .943          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Distance (million miles):              66.8          </fo:block>  <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt" font-weight="bold">              Name:              Earth          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Mass (Earth = 1):              1          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Day (Earth = 1):              1</fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Radius (in miles):              2107          </fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Density (Earth = 1):              1</fo:block>          <fo:block font-family="sans-serif" line-height="48pt"              font-size="36pt">              Distance (million miles):              128.4          </fo:block>      </fo:flow>  </fo:page-sequence>  </fo:root> 

OK, now weve created planets.fo. How can we use it to create a formatted PDF file?



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