我正在尝试使用hadoop进行一些样本数据分析,因此我找到了一些像
这样的xml数据<root>
<title>Document Title</title>
<content>Some document content.</content>
<keywords>test, document, keyword</keywords>
</root>
如何将其转换为csv即
文档标题,一些文档内容。,测试,文档,关键字
答案 0 :(得分:0)
找到XML转换样式表
那里的样式表可能会有所帮助:
<xsl:stylesheet version="1.0"
<xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:strip-space elements="*" />
<xsl:template match="/*/child::*">
<xsl:for-each select="child::*">
<xsl:if test="position() != last()">"<xsl:value-of select="normalize-space(.)"/>", </xsl:if>
<xsl:if test="position() = last()">"<xsl:value-of select="normalize-space(.)"/>" <xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
也许您想删除xsl:if标记内的引号,以便它不会将您的值放入引号,具体取决于您要使用CSV文件的位置。