Xml 如何使xsl fo表像表一样显示?
我正在尝试一个xsl fo示例,该示例本应创建一个表,但当我运行它时,它会并排显示数据,而不显示表行或单元格。如何使其正确显示 我在.xml文件中有一个样式表标记,所以当我右键单击它并选择“使用Internet explorer打开”时,它应该将其转换为.xslt文件 预期输出两个输出将在单独的行中,Xml 如何使xsl fo表像表一样显示?,xml,xslt,xsl-fo,Xml,Xslt,Xsl Fo,我正在尝试一个xsl fo示例,该示例本应创建一个表,但当我运行它时,它会并排显示数据,而不显示表行或单元格。如何使其正确显示 我在.xml文件中有一个样式表标记,所以当我右键单击它并选择“使用Internet explorer打开”时,它应该将其转换为.xslt文件 预期输出两个输出将在单独的行中, 第一办公室 第二办公室 我的代码 人事名册2.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet vers
第一办公室
第二办公室 我的代码 人事名册2.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>
人事名册2.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>
我不知道有哪种现代浏览器本机支持XSL-FO 因此,要么直接转换为HTML,要么在第二步中使用不同的XSLT将XSL-FO输出转换为HTML
第二种方法(再次转换输出)的示例如下:
<?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>
这会将第一个XSLT的输出转换为可以在浏览器中显示的HTML文件。我不知道有哪种现代浏览器本机支持XSL-FO 因此,要么直接转换为HTML,要么在第二步中使用不同的XSLT将XSL-FO输出转换为HTML
第二种方法(再次转换输出)的示例如下:
<?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>
这会将第一个XSLT的输出转换为可以在浏览器中显示的HTML文件。您不需要说明任何有关XSL FO处理器的内容。XSL FO是应用程序解释和创建输出的标记语言。这与HTML相同。。。对于HTML,浏览器解释HTML标记和CSS样式,并在浏览器中为您提供“合成”视图 要对XSL FO执行同样的操作,您可以使用一些XSL FO处理器来解释XSL FO标记并创建输出(可以是PDF或Postscript,也可以是许多其他组合输出,如AFP、PCL、XPS等)
要从XSL FO获得真正的格式化输出,您需要一个XSL FO处理器。没有浏览器能做到这一点。开源世界中有ApacheFop或商业应用程序,如RenderX XEP或AntennaHouse。您不需要说明任何有关XSL FO处理器的内容。XSL FO是应用程序解释和创建输出的标记语言。这与HTML相同。。。对于HTML,浏览器解释HTML标记和CSS样式,并在浏览器中为您提供“合成”视图 要对XSL FO执行同样的操作,您可以使用一些XSL FO处理器来解释XSL FO标记并创建输出(可以是PDF或Postscript,也可以是许多其他组合输出,如AFP、PCL、XPS等)
要从XSL FO获得真正的格式化输出,您需要一个XSL FO处理器。没有浏览器能做到这一点。开源世界中有Apache FOP或商业应用程序,如RenderX XEP或Antenahouse。如果OP想在浏览器中显示,我会完全跳过XSLFO步骤,只使用XSLT将输入XML转换为HTML。@Hobbes:我知道,我在介绍中提到过。但这也是可能的。如果OP想要在浏览器中显示,我会完全跳过XSLFO步骤,而只使用XSLT将输入XML转换为HTML。@Hobbes:我知道,我在介绍中提到过。但这也是可能的。