Re: XML to CSV



Harry wrote:
I am trying to take XML from SQL Server 2000 using "FOR XML AUTO, XMLDATA" and convert it to a CSV file using an XSLT file. Everything works fine but I cannot figure out how to include the list of field names as the first row in the CSV file. Is there an easy way and I am just missing something?

Easy, fortunately. In your template for the document root, before doing
anything else, output a list of the names of the element types (or the
field names, if different). As I don't know what your XML file looks
like, I can't say how. For example, if your XML file looked like this:

<data>
<forename>Harry</forename>
<surname>Riddle</surname>
<location>Earth</location>
</data>

You could write

<xsl:template match="/">
<xsl:for-each select="data/*">
<xsl:value-of select="name()"/>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates/>
</xsl:template>

///Peter
--
XML FAQ: http://xml.silmaril.ie/
.



Relevant Pages

  • Help :XML file data formatting ??
    ... field on the third record in the file might correspond to telephone number. ... For that I need to read this CSV file and build the proper XML file node ...
    (microsoft.public.dotnet.general)
  • Re: Complex Import Problem - PDF to XML to CSV to Access?
    ... CSV file of numeric values into one with the corresponding text values. ... What's in the XML file? ... and translate the numerical data back into the text I need. ... John Nurick [Microsoft Access MVP] ...
    (microsoft.public.access.externaldata)
  • XML parser
    ... For one of my applications I write and read some data to / from a CSV file ... Now I want to replace the CSV file by a XML file. ... because it wouldn't be too hard to code my own routine to ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Parse a CSV file in C#?
    ... Can I programmatically save the file as an Excel Workbook and then parse ... file using the Excel Namespace Methods available? ... Or can I programmatically save the CSV file as an XML file and then parse ...
    (microsoft.public.dotnet.framework.aspnet)
  • Flattening and XML Tree to a CSV
    ... Can anyone post or point me to a link that has a complete XSLT file that ... will flatten an XML tree for conversion to a CSV file? ...
    (microsoft.public.dotnet.xml)