2017-07-26 29 views
1

我需要幫助來創建基於SQL查詢的CSV文件。使用XSL從SQL查詢中創建CSV

這是當前XSL的樣子:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="text" encoding="iso-8859-1"/> 
<xsl:param name="fieldNames" select="'yes'" /> 
<xsl:template match="NewDataSet"> 
    <xsl:text></xsl:text> 
    <xsl:apply-templates select="Table"/> 
</xsl:template> 
<xsl:template match="Table"> 
    <xsl:for-each select="*"> 
     <xsl:value-of select="."/> 
     <xsl:if test="position() != last()"> 
      <xsl:value-of select="','"/> 
     </xsl:if> 
    </xsl:for-each> 
<xsl:text>&#10;</xsl:text> 
</xsl:template> 
</xsl:stylesheet> 

一切工作正常,但事實上,我需要在CSV添加標題行對每個值的預定值。我怎樣才能做到這一點?

這是現在的樣子:enter image description here

這就是我想要的CSV看起來像:enter image description here

回答

0

添加例如

<xsl:template match="/"> 
    <xsl:text>foo,bar,baz 
</xsl:text> 
    <xsl:apply-templates/> 
</xsl:template> 

其中foo,bar,baz將是您的列名稱。

+0

嗨馬丁!非常感謝! –