【发布时间】:2016-09-20 10:15:52
【问题描述】:
我正在使用 XSLT 导出过滤器将我的 OpenOffice Calc 文件的一部分提取到 XML 文件中。我的过滤器基于this SO question 中的第二个答案,它工作正常,直到我将另一个工作表添加到 Calc 文件中。
现在过滤器应用于每个工作表,因为它们完全不同,所以生成的 XML 是垃圾。
我可以指定导出时将过滤器应用到哪个工作表吗?喜欢使用工作表的名称或订单位置?
编辑:
Excel 看起来 like this。
如您所见,还有第二个工作表,我想应用另一个 XSLT 过滤器。
目前屏幕截图中表格的过滤器看起来像这样(当只有一个电子表格时它可以正常工作):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" exclude-result-prefixes="office table text">
<xsl:template match="/">
<command name="CreateTitle">
<xsl:apply-templates select="/*/office:body" />
</command>
</xsl:template>
<xsl:template match="office:body">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="office:spreadsheet">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="office:spreadsheet/table:table">
<title><xsl:value-of select="table:table-row[2]/table:table-cell[1]/text:p" /></title>
<titleDesc><xsl:value-of select="table:table-row[2]/table:table-cell[2]/text:p" /></titleDesc>
<institute><xsl:value-of select="table:table-row[2]/table:table-cell[3]/text:p" /></institute>
<contractType><xsl:value-of select="table:table-row[2]/table:table-cell[4]/text:p" /></contractType>
</xsl:template>
</xsl:stylesheet>
这是输入格式:http://pastebin.com/tLyFKU4e(有点长)
【问题讨论】:
-
尝试将
<xsl:template match="office:body"><xsl:apply-templates /></xsl:template>更改为<xsl:template match="office:body"><xsl:apply-templates select="office:spreadsheet[1]"/></xsl:template>以尝试根据位置进行处理。我对 OpenOffice 的 XML 格式不熟悉,请自行尝试。 -
感谢您的建议,但遗憾的是没有奏效。我也尝试用谷歌搜索这种语法,但找不到任何东西。
-
将
<xsl:apply-templates select="office:spreadsheet[1]"/>更改为<xsl:apply-templates select="descendant::office:spreadsheet[1]"/>会改善情况吗?正如我所说,我不熟悉确切的 XML 格式,因此除非您编辑问题并向我们展示它猜测的输入示例。 -
遗憾的是这也没有帮助(生成的 XML 为空)。我编辑了更多信息,希望对您有所帮助。
-
尝试写一个简单的样式表只做
<xsl:template match="/"><xsl:copy-of select="."/></xsl:template>,然后你应该看到输入格式,你可以发布它
标签: xml xslt openoffice.org openoffice-calc