Creating Block-Level Content: fo:block

Creating Block-Level Content: <fo:block>

Blocks are essential in XSL-FO; you use blocks in XSL-FO to create rectangular display areas set off from other display areas in a document. You can use the <fo:block> formatting object for formatting such items as paragraphs, titles, headlines, figure and table captions, and so on. Heres an example from the beginning of the chapter where Im creating a block element and specifying various properties and the text in the block:

 <fo:block font-family="Times" line-height="48pt" font-size="36pt">      Welcome to XSL formatting.  </fo:block> 

You can use the following properties with <fo:block> :

  • Common accessibility properties: source-document, role

  • Common aural properties: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume

  • Common border, padding, and background properties: background-attachment , background- color , background-image, background-repeat , background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border-bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right

  • Common font properties: font-family, font-size, font-stretch, font-size-adjust, font-style, font-variant, font-weight

  • Common hyphenation properties: country, language, script, hyphenate , hyphenation-character, hyphenation-push-character-count, hyphenation- remain -character-count

  • Common margin properties for blocks: margin-top, margin-bottom, margin-left, margin-right, space-before, space-after, start-indent, end-indent

  • break-after

  • break-before

  • color

  • font-height-override-after

  • font-height-override-before

  • hyphenation-keep

  • hyphenation-ladder-count

  • id

  • keep-together

  • keep-with- next

  • keep-with-previous

  • last-line-end-indent

  • linefeed -treatment

  • line-height

  • line-height-shift-adjustment

  • line-stacking-strategy

  • orphans

  • relative-position

  • space-treatment

  • span

  • text-align

  • text-align-last

  • text-indent

  • visibility

  • white-space -collapse

  • widows

  • wrap-option

  • z-index

For example, I can add the title The Planets Table to the document by choosing Times font (currently, fop comes with the Times, Helvetica, Courier, Symbol, sans-serif, serif, and ZapfDingbats fonts built in), in the fontfamily property, 36-point font size by setting the font-size property, and boldface by setting the font-weight property to bold. I set the height of the block with the line-height property and display the title in blue with the color property:

 <?xml version="1.0"?>  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      xmlns:fo="http://www.w3.org/1999/XSL/Format"      version="1.0">      <xsl:template match="PLANETS">          <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">              <fo:layout-master-set>              .              .              .              </fo:layout-master-set>              <fo:page-sequence master-name="page">                  <fo:flow flow-name="xsl-region-body">                      <fo:block font-weight="bold" font-size="36pt"                          line-height="48pt" font-family="Times"                          color="blue">                          The Planets Table                      </fo:block>                      <xsl:apply-templates/>                  </fo:flow>              </fo:page-sequence>      .      .      . 

That creates the title block you see at the top of the text in Figure 11.1. I can create similar blocks for each data item of each planet by using XSLT templates this way. Note also that Im listing the name of each planet in italics by setting the font-style property to italic, and Im underlining other text by using the text-decoration property of <fo:inline> elements, which youll see in the next chapter:

 <?xml version="1.0"?>  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      xmlns:fo="http://www.w3.org/1999/XSL/Format"      version="1.0">      <xsl:template match="PLANETS">          <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">              <fo:layout-master-set>              .              .              .               </fo:layout-master-set>               <fo:page-sequence master-name="page">              .              .              .               </fo:page-sequence>          </fo:root>      </xsl:template>      <xsl:template match="PLANET/NAME">          <fo:block font-weight="bold" font-size="28pt"              line-height="48pt" font-family="Times"              font-style="italic">              Planet:              <xsl:apply-templates/>          </fo:block>      </xsl:template>      <xsl:template match="PLANET/MASS">          <fo:block font-size="24pt" line-height="32pt"              font-family="Times">              <fo:inline text-decoration="underline">                  Mass              </fo:inline>:              <xsl:apply-templates/>              [Earth = 1]          </fo:block>      </xsl:template>          .          .          .  </xsl:stylesheet> 

And thats it. Youve created your first XML to XSL-FO transformation, transforming planets.xml into planets.fo. The fop processor will create planets.pdf from planets.fo, and you can refer to Figure 11.1 to see the results.

This transformation formatted the data in planets.xml and displayed that data in blocks, one after the next. On the other hand, in earlier chapters you saw the planetary data in planets.xml displayed in a table. Can you do that in XSL-FO? No problem.



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

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