|
next
|
Subject: Small problem during conversion of XML to CSV Author: Kalyan Tummala Date: 26 Mar 2008 02:44 PM
|
Pardon me if such a post has been posted earlier.
I am supposed to write a style sheet for converting an XML into CSV. I did that. But the problem I am getting is that some of the coloumns in the XML already have commas in them. So, when I open the CSV sheet using Excel some of the coloumns are getting moved to the right.
I hope I am being clear in explaining my problem. One solution I thought of was to put such coloumns in double quotes. But I have no idea how to do that. :(
Here is the XSL I wrote
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="abc.xml" --><!DOCTYPE xsl:stylesheet [
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="separator" select="','"/>
<xsl:value-of select="concat('PROGRAMID', $separator, 'PROGTITLE', $separator, 'PROGLOC', $separator, 'LOCATION', $separator, 'PROGADDR', $separator, 'CITY', $separator, 'STATE', $separator, 'ZIP', $separator, 'UPDATEDATE', $separator, 'PROGURL', $separator, 'IMPACTAREA', $separator, 'LONGITUDE', $separator, 'LATITUDE' )"/><xsl:text>
</xsl:text>
<xsl:for-each select="xmlServiceResponse/body/searchResults/programLocation">
<xsl:value-of select="concat(programSeries/@uid, $separator, title, $separator, address/@uid, $separator, address/name, $separator, address/buildingNumber, $separator, address/city, $separator, address/state, $separator, address/postalCode, $separator, @momentModified, $separator, url, $separator, primaryImpactArea/impactArea/name, $separator, address/geoposition/@longitude, $separator, address/geoposition/@latitude)"/><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I am also attaching the XML along with this
P.S: As I need only some of the coloumns from the style sheet i just took them and named them in a different way.
abc(1).xml This is the XML file
|
next
|
Subject: Small problem during conversion of XML to CSV Author: James Durning Date: 26 Mar 2008 04:54 PM
|
<xsl:variable name="quot" select="""/>
<xsl:variable name="seperator2" select="concat($quot, $seperator, $quot)"/>
<xsl:for-each select="xmlServiceResponse/body/searchResults/programLocation">
<xsl:value-of select="concat($quot, programSeries/@uid, $separator2, title, $separator2, address/@uid, $separator2, address/name, $separator2, address/buildingNumber, $separator2, address/city, $separator2, address/state, $separator2, address/postalCode, $separator2, @momentModified, $separator2, url, $separator2, primaryImpactArea/impactArea/name, $separator2, address/geoposition/@longitude, $separator2, address/geoposition/@latitude), $quot;"/><xsl:text>
</xsl:text>
|
|
|
|