XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Kalyan TummalaSubject: 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.


Unknownabc(1).xml
This is the XML file

Postnext
James DurningSubject: Small problem during conversion of XML to CSV
Author: James Durning
Date: 26 Mar 2008 04:54 PM
<xsl:variable name="quot" select="&quot;"/>
<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>

Postnext
Kalyan TummalaSubject: Small problem during conversion of XML to CSV
Author: Kalyan Tummala
Date: 27 Mar 2008 05:21 PM
I tried that and I got the error as below

XPathParserException: A string literal is not terminated. A '"' or "'" is missing. expression = '"' Remaining tokens are: () (test2.xsl, line 22, column 48)


The line 22 is

<xsl:variable name="quot" select="&quot;"/>

Posttop
Kalyan TummalaSubject: Small problem during conversion of XML to CSV
Author: Kalyan Tummala
Date: 27 Mar 2008 06:05 PM
ohh... I corrected that error. Newez thanks for giving me the idea that &quot can be used.

Thanks again

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.