我一直在致力於xml轉換爲csv並使用Convert an XML file to CSV file using java方法。但是,我的.xsl文件不能生成預期的.csv結果。使用XSL轉換將XML轉換爲CSV
我該怎麼辦?我應該如何更改我的.xsl文件?
這裏是我的.xml文件:
<RowOfValues>
<RowValue>
<Value>XYZ</Value>
</RowValue>
<RowValue>
<Value>xyz1</Value>
</RowValue>
<RowValue>
<Value>xyz2</Value>
</RowValue>
<RowValue>
<Value>xyz3</Value>
</RowValue>
<RowValue>
<Value>xyz4</Value>
</RowValue>
</RowOfValues>
<RowOfValues>
<RowValue>
<Value>ABC</Value>
</RowValue>
<RowValue>
<Value>abc1</Value>
</RowValue>
<RowValue>
<Value>abc2</Value>
</RowValue>
<RowValue>
<Value>abc3</Value>
</RowValue>
<RowValue>
<Value>abc4</Value>
</RowValue>
</RowOfValues>
這裏是我的.xsl文件:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
RowValue,Value
<xsl:for-each select="//RowOfValues">
<xsl:for-each select="//RowValue">
<xsl:value-of select="concat(Value,',','
')"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
當前結果(CSV):
RowValue ,價值
XYZ,
xyz1,
xyz2,
xyz3,
xyz4,
ABC,
abc1,
abc2,
abc3,
abc4,
預期結果(CSV):
RowValue,Value
XYZ ABC
xyz1,abc1
xyz2,abc2
xyz3,abc3
xyz4,abc4
這不是一個有效的XML文檔,因爲它沒有根元素。 – samjudson
@samjudson你是對的,但我沒有出現所有的XML文件。 – user3560030