简体   繁体   English

如何使xsl-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. 我正在尝试一个应该制作表的xsl-fo示例,但是当我运行它时,它并排显示了没有表行或单元格的数据。 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. 我在.xml文件中有一个样式表标签,因此当我右键单击它并选择“使用Internet Explorer打开”时,它应该与.xslt文件一起翻译。

Expected output the two outputs will be in seperate rows, 预期输出,两个输出将在单独的行中,
FO First Office FO第一办公室
FO Second Office FO第二办公室

My Code 我的密码

personnel_roster2.xslt person_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 person_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>

I don't know of a modern browser that natively supports XSL-FO. 我不知道原生支持XSL-FO的现代浏览器。

So either you directly transform to HTML or transform your XSL-FO output to HTML in a second step with a different XSLT. 因此,您可以直接使用另一XSLT将其转换为HTML,或者将您的XSL-FO输出转换为HTML。


An example of the second approach, transforming the output again, is: 第二种方法的示例,再次转换输出,是:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/fo:root/fo:page-sequence/fo:flow">
        <html>
            <body>
                <xsl:for-each select="fo:table">
                    <table border="1">
                        <xsl:for-each select="fo:table-row">
                            <tr>
                                <xsl:for-each select="fo:table-cell">
                                    <td style="font-weight:{fo:block/@font-weight};">
                                        <xsl:value-of select="fo:block" />
                                    </td>
                                </xsl:for-each>
                            </tr>
                        </xsl:for-each>
                    </table>
                </xsl:for-each>
            </body>
        </html>
     </xsl:template>    

</xsl:stylesheet>

This transforms the output of the first XSLT to a HTML file which can be displayed in the browser. 这会将第一个XSLT的输出转换为可以在浏览器中显示的HTML文件。

You do not state anything about an XSL FO processor. 您没有声明有关XSL FO处理器的任何信息。 XSL FO is a markup language that an application interprets and creates an output. XSL FO是应用程序解释并创建输出的标记语言。 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. 这与HTML相同……对于HTML,浏览器解释HTML标记和CSS样式,并在浏览器中为您提供“组合”视图。

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, ...) 要对XSL FO进行同样的操作,您可以使用一些XSL FO处理器来解释XSL FO标记并创建输出(可以是PDF或Postscript或许多其他组合输出,例如AFP,PCL,XPS等)。

To get true formatted output from XSL FO you need an XSL FO processor. 要从XSL FO获得真实的格式化输出,您需要一个XSL FO处理器。 No browser does this. 没有浏览器会这样做。 THere is Apache FOP in the open source world or commercial applications like RenderX XEP or AntennaHouse. Tere是开源世界或RenderX XEP或AntennaHouse等商业应用程序中的Apache FOP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM