使用 xslt 过滤器从 Calc 导出时出现 OpenOffice 错误
我在 Calc 中有一个基于行的数据,我想使用 xslt 过滤器将其导出到 xml。除非两个相邻列中的值相同,否则过滤器正常工作。例如,参见下面的数据...
SrNo Col2 Col3 Col4 Col5 1 PQR 123 567 LMN 2 OPQ 665 786 BCD 3 EUR 443 443 UFF 4 OLE 345 887 JAS 5 EJR 565 565 OEP
对于上面的数据,此错误仅发生在第 3 行和第 5 行。由于某种原因,过滤器会跳过 col4 并从 col5 中获取值。对于其余数据,导出效果非常好。这是 xslt 代码...
<row>
<col1><xsl:value-of select="table:table-cell[1]"/></col1>
<col2><xsl:value-of select="table:table-cell[2]"/></col2>
<col3><xsl:value-of select="table:table-cell[3]"/></col3>
<col4><xsl:value-of select="table:table-cell[4]"/></col4>
<col5><xsl:value-of select="table:table-cell[5]"/></col5>
</row>
有人可以对此提供任何意见吗?这很奇怪,因此我陷入了困境。顺便说一句,我正在使用 OpenOffice 3.1.1(Build 9420)和 xslt 2.0。
I have a row-based data in Calc which I want to export to xml using xslt filters. The filters work properly except when values in two adjacent columns are the same. For example, see the data below ...
SrNo Col2 Col3 Col4 Col5 1 PQR 123 567 LMN 2 OPQ 665 786 BCD 3 EUR 443 443 UFF 4 OLE 345 887 JAS 5 EJR 565 565 OEP
For the above data, this error occurs only for lines 3 and 5. For some reason, the filter skips col4 and takes the value from col5. For rest of the data the export works perfectly fine. Here is the xslt code ...
<row>
<col1><xsl:value-of select="table:table-cell[1]"/></col1>
<col2><xsl:value-of select="table:table-cell[2]"/></col2>
<col3><xsl:value-of select="table:table-cell[3]"/></col3>
<col4><xsl:value-of select="table:table-cell[4]"/></col4>
<col5><xsl:value-of select="table:table-cell[5]"/></col5>
</row>
Can someone please give any inputs on this ? It's pretty weird and I am badly stuck up due to this. Btw, I am using OpenOffice 3.1.1 (Build 9420) with xslt 2.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是伟大的代码罗希特;它确实帮助我走向了正确的方向。我很难让 XSLT 2.0 代码在我的 LibreOffice 安装中工作,因此我将代码转换为使用 XSLT 1.0(命名模板而不是函数调用,以及能够将节点传递到递归函数中的扩展)。如果有人需要它,我的代码如下。请注意,它不是通用代码 - 您需要将我的字段替换为您自己的字段。
此特定示例将电子表格导出到 XCode 可以识别的有效 .plist 文件中。它已经在 Vista 上运行的 LibreOffice 3.5 上进行了测试。
That was great code Rohit; it definitely helped send me in the right direction. I was having a hard time getting the XSLT 2.0 code working in my LibreOffice installation, so I converted the code to use XSLT 1.0 (named templates instead of functions calls, and an extension to be able to pass a node into the recursive function). In case someone needs it, my code is below. Note that it is not general purpose code - you will need to replace my fields with your own.
This particular example exports a spreadsheet into a valid .plist file that is recognized by XCode. It has been tested with LibreOffice 3.5 running on Vista.
该问题是由于工作表基础数据结构中的 table:table-cell 元素的 number-columns-repeated 属性造成的。欲了解更多详情,请参阅http:// user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=29674 和 http://user.services.openoffice.org/en /forum/viewtopic.php?f=9&t=11865。
尽管后一个链接声称已经解决了问题,但该解决方案并不完全是我想要的。我需要一个简单的基于索引的解决方案,它允许更灵活的 xml 生成。这是我试图解决的问题。
我使用 xslt 2.0 来利用用户定义的函数。这是样式表...
上面使用的标签只是占位符。请将它们替换为您的 xslt 中适当的内容。此解决方案受到 xslt 处理器允许的递归调用数量的限制。
如果xslt 1.0支持将节点作为参数发送,那么我们可以尝试替换上面的udf以获得基于模板的解决方案。如果您发现任何错误,请告诉我。
The issue is due to number-columns-repeated attribute to table:table-cell element in the sheet's underlying data structure. For more details, please refer to http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=29674 and http://user.services.openoffice.org/en/forum/viewtopic.php?f=9&t=11865.
Though the latter link claims to have resolved the issue, the solution is not quite what I was looking for. I required a simple index-based solution which allows a more flexible xml generation. Here is what I tried to work out.
I have used xslt 2.0 to make use of user defined functions. Here is the stylesheet ...
The tags used above are just placeholders. Please replace them with appropriate ones in your xslt. This solution is limited by number of recursive calls allowed by the xslt processor.
If xslt 1.0 supports sending node as params, then we can try to replace the above udf to get a template based solution. If you find any bugs, do let me know.
马塞尔的解决方案看起来很复杂,但效果很完美,而且适应起来并不复杂。
所以,再次向大家简述一下:
您基本上将整个模板复制并粘贴到您的 xsl 中:
然后,将所有标准表:行(失败)替换为
确保调整“colIndex”值,但将 currentIndex 保留为 1!
最后,将标题的 xt 行添加到您的标题中。
完美,马塞尔!
Marcel's solution looks complicated, but works perfect and is not so complicated to adapt.
So, again in short for everybody:
You basically copy&paste the whole template into your xsl:
Then, replace all the standard table:row (which is failing) with
Be sure to adjust the "colIndex" values, but leave the currentIndex on 1!
Finally, add the xt lines of the header to yours.
Perfect, Marcel!