XSL-FO to make a table


/ Published in: XSLT
Save to your folder(s)

I am trying to get the table to lay itself out so that the column headers wrap in preference to the table cell values. Any ideas how to achieve this?


Copy this code and paste it in your HTML
  1. <?xml version="1.0"?>
  2. <fo:root writing-mode="lr-tb" hyphenate="true" text-align="justify" role="html:html" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:html="http://www.w3.org/1999/xhtml">
  3. <fo:layout-master-set>
  4. <fo:simple-page-master page-width="auto" page-height="auto" master-name="all-pages">
  5. <fo:region-body margin-top="0.75in" margin-right="0.75in" margin-bottom="0.75in" margin-left="0.75in" column-count="1" column-gap="12pt" />
  6. <fo:region-before region-name="page-header" extent="0.75in" display-align="before" />
  7. <fo:region-after region-name="page-footer" extent="0.75in" display-align="after" />
  8. <fo:region-start extent="0.75in" />
  9. <fo:region-end extent="0.75in" />
  10. </fo:simple-page-master>
  11. </fo:layout-master-set>
  12. <fo:page-sequence master-reference="all-pages">
  13. <fo:title />
  14. <fo:static-content flow-name="page-header">
  15. <fo:block font-size="small" text-align="center" space-before.conditionality="retain" space-before="0.25in" />
  16. </fo:static-content>
  17. <fo:static-content flow-name="page-footer">
  18. <fo:block font-size="small" text-align="center" space-after.conditionality="retain" space-after="0.25in">
  19. <fo:block space-before="0.67em" space-after="0.67em" border="1px inset" space-before.minimum="0.5em" space-before.optimum="0.67em" space-before.maximum="0.92em" space-after.minimum="0.5em" space-after.optimum="0.67em" space-after.maximum="0.92em" />
  20. <fo:float float="right">
  21. <fo:block width="3cm" text-align="right">Page <fo:page-number /> of <fo:page-number-citation ref-id="last-page-marker" /></fo:block>
  22. </fo:float>
  23. </fo:block>
  24. </fo:static-content>
  25. <fo:flow flow-name="xsl-region-body">
  26. <fo:block font-size="0.6em" role="html:body">
  27.  
  28. <fo:block role="html:div" keep-together="always">
  29. <fo:table-and-caption display-align="center">
  30. <fo:table border-collapse="collapse" border-spacing="2px" border="1px solid black" role="html:table" id="EndOfLifeBreakdownByComponent" keep-together="always">
  31. <fo:table-header start-indent="0pt" end-indent="0pt" text-indent="0pt" last-line-end-indent="0pt" text-align="start" text-align-last="relative" role="html:thead">
  32. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  33. <fo:block>Column1</fo:block>
  34. </fo:table-cell>
  35. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  36. <fo:block>Column2</fo:block>
  37. </fo:table-cell>
  38. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  39. <fo:block>Column3
  40. Header</fo:block>
  41. </fo:table-cell>
  42. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  43. <fo:block>Column4
  44. header
  45. is longer
  46. </fo:block>
  47. </fo:table-cell>
  48. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  49. <fo:block>Column5
  50. Header
  51. </fo:block>
  52. </fo:table-cell>
  53. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  54. <fo:block>Column6
  55. Header
  56. Header
  57. Header
  58. </fo:block>
  59. </fo:table-cell>
  60. <fo:table-cell linefeed-treatment="preserve" wrap-option="wrap" font-weight="bold" text-align="center" border="1px solid black" padding="1px" >
  61. <fo:block>Column7
  62. Donkey
  63. Donkey
  64. Donkey
  65. </fo:block>
  66. </fo:table-cell>
  67. </fo:table-header>
  68. <fo:table-body start-indent="0pt" end-indent="0pt" text-indent="0pt" last-line-end-indent="0pt" text-align="start" text-align-last="relative" role="html:tbody">
  69. <fo:table-row role="html:tr">
  70. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  71. <fo:block>This is a fairly long piece of text.</fo:block>
  72. </fo:table-cell>
  73. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  74. <fo:block>This is an even longer piece of text - I don't mind this wrapping</fo:block>
  75. </fo:table-cell>
  76. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  77. <fo:block>N/A</fo:block>
  78. </fo:table-cell>
  79. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  80. <fo:block>N/A</fo:block>
  81. </fo:table-cell>
  82. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  83. <fo:block>0.65</fo:block>
  84. </fo:table-cell>
  85. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  86. <fo:block>N/A</fo:block>
  87. </fo:table-cell>
  88. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  89. <fo:block>N/A</fo:block>
  90. </fo:table-cell>
  91. </fo:table-row>
  92.  
  93.  
  94. </fo:table-body>
  95. <fo:table-body start-indent="0pt" end-indent="0pt" text-indent="0pt" last-line-end-indent="0pt" text-align="start" text-align-last="relative" role="html:tbody">
  96. <fo:table-row role="html:tr">
  97. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  98. <fo:block>Total</fo:block>
  99. </fo:table-cell>
  100. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  101. <fo:block />
  102. </fo:table-cell>
  103. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  104. <fo:block />
  105. </fo:table-cell>
  106. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  107. <fo:block />
  108. </fo:table-cell>
  109. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  110. <fo:block>8.7</fo:block>
  111. </fo:table-cell>
  112. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  113. <fo:block />
  114. </fo:table-cell>
  115. <fo:table-cell text-align="center" border="1px solid black" padding="1px" >
  116. <fo:block>0.0</fo:block>
  117. </fo:table-cell>
  118. </fo:table-row>
  119. </fo:table-body>
  120. </fo:table>
  121. </fo:table-and-caption>
  122. </fo:block>
  123.  
  124. </fo:block>
  125. <fo:block id="last-page-marker" />
  126. </fo:flow>
  127. </fo:page-sequence>
  128. </fo:root>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.