我有一个 .ods 文件,想通过给定行的第一列的值访问 table-cell
s 中 table-row
s 的值。所以他们的标题在我的情况下。
所以计算表看起来像这样:
First_Name | Last_Name
Peter | Parker
Emma | Stone
...
这是我的 xslt-export-filter 文件:
SuperBasicExportFilter.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
exclude-result-prefixes="table text office"
>
<xsl:output
method="xml"
indent="yes"
encoding="UTF-8"
omit-xml-declaration="no"
/>
<xsl:template match="/">
<xsl:variable name="columnHeadings">
<xsl:for-each select="//table:table/table:table-row[not(preceding::table:table-row)]//table:table-cell">
<xsl:element name="heading">
<xsl:attribute name="name" select="text:p" />
<xsl:value-of select="position()" />
</xsl:element>
</xsl:for-each>
</xsl:variable>
<html>
<body>
<h1>Hello</h1>
<xsl:message>columnHeadings: <xsl:value-of select="$columnHeadings" /></xsl:message>
<table>
<xsl:for-each select="//table:table/table:table-row">
<xsl:if test="position() > 1">
<tr>
<td>
First Column Value
<xsl:value-of select="table:table-cell[1]/text:p" />
<!-- <xsl:value-of select="table:table-cell[$columnHeadings/heading[@name='First_Name']]/text:p" /> -->
</td>
<td>
Second Column Value
<xsl:value-of select="table:table-cell[2]/text:p" />
<!-- <xsl:value-of select="table:table-cell[$columnHeadings/heading[@name='Last_Name']]/text:p" /> -->
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
消息显示“columnHeadings: 1234567891011121314”等。所以它正在正确设置位置值。
我尝试根据“标题”元素的“名称”属性获取值。 但我无法以任何方式单独获得这些值。看来我不能将 $columnHeadings 与任何 XPath 表达式一起使用。它只是返回“Xpath 评估没有返回结果”。
我试过了
<xsl:variable name="columnHeadingsNode" select="document('')//xsl:variable[@name = 'columnHeadings']" />
然后得到值xsl:key
之类的 <xsl:key name="columnHeadings" match="//table:table/table:table-row[not(preceding::table:table-row)]//table:table-cell" use="text:p" />
元素 - 但这样我就无法根据“名称”访问它还有什么我可以尝试使用 xpath 表达式访问变量内容?
甚至有可能访问像 table:table-cell[$columnHeadings/heading[@name='Last_Name']]
? 的值吗?