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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.