试图将其转换为:
<list>
<entry>
<parentFeed>
<feedUrl>http://rss.nzherald.co.nz/rss/xml/nzhrsscid_000000001.xml</feedUrl>
<id>68</id>
</parentFeed>
<content>Schools will have to put up with problematic pay administered through Novopay for another eight weeks after the Government announced it would persist with the unstable system.Minister responsible for Novopay, Steven Joyce, delayed...</content>
<link>http://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=10872300&ref=rss</link>
<title>Novopay: Govt sticks with unstable system</title>
<id>55776</id>
<published class="sql-timestamp">2013-03-19 03:38:55.0</published>
<timestamp>2013-03-19 07:31:16.358 UTC</timestamp>
</entry>
</list>为此,使用XSLT:
Title, Link, Date
Novopay: Govt sticks with unstable system, http://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=10872300&ref=rss, 2013-03-19 03:38:55.0但是,尽管我可能尝试,我无法摆脱在文件开头的空白行。我的样式表如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:csv="csv:csv"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/list"> <xsl:for-each select="entry">
Title, Link, Date
<xsl:value-of select="title"/>, <xsl:value-of select="link"/>, <xsl:value-of select="published"/>
</xsl:for-each></xsl:template>
</xsl:stylesheet>我尝试按照建议的<xsl:text>
</xsl:text>添加这里,它删除了最后一个行段,所以我将它移到文件的顶部,这时它变成了一个不操作。解决方案这里实际上添加了一个空行(根据ascii手册,这很有意义,因为十六进制代码是换行符)。
作为解决办法,我一直在使用Java来生成CSV输出。
不过,我确实觉得XSLT的速度要快得多,因为它的设计目的是将XML转换成各种其他格式。类似的XSLT可以完美地生成HTML、RSS和ATOM提要。
发布于 2013-03-21 12:09:08
你做得很好,你的逻辑是正确的。但是,当输出XSLT中的所有缩进都会影响输出时,需要注意的是,XSLT应该如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:csv="csv:csv"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/list"> <xsl:for-each select="entry">Title, Link, Date
<xsl:value-of select="title"/>, <xsl:value-of select="link"/>, <xsl:value-of select="published"/>
<xsl:text>
</xsl:text>
</xsl:for-each></xsl:template>
</xsl:stylesheet>运行上面的XSLT,它将完美地工作。
https://stackoverflow.com/questions/15546456
复制相似问题