使用 Xsl 样式表,我将输出 XML 文件(从我的工具获得)格式化为 Excel(xls 文件)。在此,我只想删除一段文字。我正在使用 fo:inline 来实现如下所示:
<fo:block>
<fo:inline text-decoration="line-through">Hello World</fo:inline>
</fo:block>
但这不起作用,我在这里用错了什么?任何提示都会非常有用。 只是为了测试,我尝试使用下划线装饰,但这也不起作用。
我的XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:fo="https://www.w3.org/TR/xsl/#fo_flow"
xmlns:format="http://www.w3.org/1999/XSL/Format">
<xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction>
<xsl:template match="/">
<xsl:call-template name="generateReportPage">
<xsl:with-param name="title" select="'Report'"/>
<xsl:with-param name="subtitle1" select="'Overview'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="generateReportPage">
<xsl:param name="title"/>
<xsl:param name="subtitle1"/>
<xsl:variable name="changeSummaryEle" select="/plm:PLMXML/plm:ChangeSummaryElement"/>
<xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="heading1">
<Font ss:Color="#0000FF" ss:Size="20" ss:FontName="Arial" ss:Bold="1"/>
<Interior ss:Color="#CCCCFF" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="heading2">
<Font ss:Color="#0000FF" ss:Size="12" ss:FontName="Arial" ss:Bold="1"/>
<Interior ss:Color="#CCCCFF" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="heading3">
<Alignment ss:Horizontal="Left"/>
<Font ss:Color="#000000" ss:Size="10" ss:FontName="Arial" ss:Bold="1"/>
<Interior ss:Color="#CCCCFF" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="cell_data">
<Font ss:Color="#000000"/>
<Interior ss:Color="#FFFFCC" ss:Pattern="Solid"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="60" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="60" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="100" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="100" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Column ss:AutoFitWidth="0" ss:Width="80" AutoFitWidth="1"/>
<Row>
<Cell ss:StyleID="heading1">
<Data ss:Type="String">
<xsl:value-of select="$title"/>
</Data>
</Cell>
<Cell ss:StyleID="heading1"></Cell>
</Row>
<Row></Row>
<Row>
<Cell ss:StyleID="heading2">
<Data ss:Type="String">
<xsl:value-of select="$subtitle1"/>
</Data>
</Cell>
<Cell ss:StyleID="heading2"></Cell>
</Row>
<Row>
<Cell ss:StyleID="heading3">
<Data ss:Type="String">
Date:
</Data>
</Cell>
<Cell ss:StyleID="heading3">
<Data ss:Type="String">
<xsl:value-of select="$report_date"/>
</Data>
</Cell>
<Cell ss:StyleID="heading2"></Cell>
</Row>
<Row></Row>
<xsl:variable name="occStr">
<xsl:text>Hello Application</xsl:text>
</xsl:variable>
<xsl:call-template name="createCL">
<xsl:with-param name="occStr" select="$occStr"/>
</xsl:call-template>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
<xsl:template name="createCL">
<xsl:param name="occid"/>
<xsl:variable name="strikedOldValue">
<fo:block>
<fo:inline text-decoration="line-through">Hello World</fo:inline>
</fo:block>
</xsl:variable>
<xsl:variable name="displayValue">
<xsl:value-of select="concat($occid, ' ', $strikedOldValue)" />
</xsl:variable>
<Data ss:Type="String">
<div>
<xsl:value-of select ="$displayValue"/>
</div>
</Data>
</xsl:template>
我也不明白 XSL_FO 与此有什么关系。
显然您正在尝试生成
Excel 2002/2003 XML
格式的文件。我相信您需要在 Styles
元素中定义样式:
<Style ss:ID="strike">
<Font ss:StrikeThrough="1"/>
</Style>
然后将单元格格式设置为:
<Cell ss:StyleID="strike">
<Data ss:Type="String">
<xsl:value-of select="$yourtext"/>
</Data>
</Cell>
未经测试,因为我没有 Excel。