2017-07-26 30 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

嗨马丁!非常感谢! –