Re: XML to CSV
- From: Peter Flynn <peter.nosp@xxxxxxxxxxxxx>
- Date: Fri, 19 May 2006 22:38:01 +0100
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>
</xsl:text>
<xsl:apply-templates/>
</xsl:template>
///Peter
--
XML FAQ: http://xml.silmaril.ie/
.
- Prev by Date: Generate SQL Server tables from an XSD
- Next by Date: Re: Little discussion about XML field performance
- Previous by thread: Generate SQL Server tables from an XSD
- Next by thread: Re: Little discussion about XML field performance
- Index(es):
Relevant Pages
|