Search code examples
xmlxsltxsl-fo

How do I get my xsl-fo table to display like a table?


I am trying out an xsl-fo example that is supposed to make a table, but when I run it it shows the data side by side without table rows or cells. How do I make it display correctly?

I have a stylesheet tag in the .xml file so when I right click it and choose Open with Internet explorer, it should translate it with the .xslt file.

Expected output the two outputs will be in seperate rows,
FO First Office
FO Second Office

My Code

personnel_roster2.xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match='/rows'>
        <fo:root>

          <fo:layout-master-set>
            <fo:simple-page-master master-name="hello"
                        page-height="11in"  page-width="8.5in" margin-top="1in" 
                        margin-bottom="1in" margin-left="0in" margin-right="1in">
              <fo:region-body margin-top="1in" margin-bottom=".5in"/>
            </fo:simple-page-master>
          </fo:layout-master-set>

            <fo:page-sequence master-reference="hello">
                <fo:flow flow-name="xsl-region-body">
                    <fo:table>
                        <xsl:for-each select="row">
                            <fo:table-row>
                                <fo:table-cell>
                                    <fo:block font-weight="bold"><xsl:value-of select="@Office"/></fo:block>
                                </fo:table-cell>
                                <fo:table-cell>
                                    <fo:block font-weight="bold"><xsl:value-of select="@OfficeTitle"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </xsl:for-each>
                    </fo:table>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

personnel_roster2.xml

<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "personnel_roster2.xslt"?> 
<rows appMode="DEV" dateGenerated="">
    <row OfficeID="32" OfficeOutputOrder="1" Office="FO" OfficeTitle="First Office" RoomFaxID="88" RoomFaxNumber="" RoomNumberID="123">
        <personnel>
            <person PersonnelID="3870" Name="The Boss" PositionRoomNumberID="31" phone="555-647-5770" PAETitle="" PositionEmployeeTypeID="C" PositionOutputOrder="1" />
        </personnel>
        <officeFaxes>
             <fax RoomNumberID="123" RoomFaxNumber="" OfficeID="32" />
        </officeFaxes>
    </row>
    <row OfficeID="33" OfficeOutputOrder="1" Office="FO" OfficeTitle="Second Office" RoomFaxID="88" RoomFaxNumber="" RoomNumberID="123">
        <personnel>
            <person PersonnelID="3870" Name="The Boss" PositionRoomNumberID="31" phone="555-647-5770" PAETitle="" PositionEmployeeTypeID="C" PositionOutputOrder="1" />
        </personnel>
        <officeFaxes>
             <fax RoomNumberID="123" RoomFaxNumber="" OfficeID="33" />
        </officeFaxes>
    </row>
</rows>

Solution

  • You do not state anything about an XSL FO processor. XSL FO is a markup language that an application interprets and creates an output. This is the same as HTML ... for HTML the browser interprets the HTML tags and CSS styles and give you a "composed" view in the browser.

    To do the same with XSL FO, you use some XSL FO processor which interprets the XSL FO markup and creates output (could be PDF or Postscript or many other composed outputs like AFP, PCL, XPS, ...)

    To get true formatted output from XSL FO you need an XSL FO processor. No browser does this. THere is Apache FOP in the open source world or commercial applications like RenderX XEP or AntennaHouse.