Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Escape output in XSLT

Posted on 2010-09-01
5
Medium Priority
?
576 Views
Last Modified: 2012-05-10
I have an XSLT stylesheet that converts XML into CSV formatted data. This stylesheet works perfectly except for the fact that if the data contains commas the CSV output obviously gets its columns mixed up. What I want to know is how I can escape these characters, and also what characters I should worry about (is it just commas that can mess me up in CSV formatted files)?
0
Comment
Question by:Blowfelt82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:apresence
ID: 33575344
Please post a sample of your output, and XSLT file.
0
 

Expert Comment

by:asutorius
ID: 33577693
Do you truly want to escape the commas or do you need them in the CSV? Are the commas vital parts of the data?

I was wondering if this article applies to you, specifically steps 2 and 3 where they recursively step through keeping the commas:
http://www.dpawson.co.uk/xsl/sect2/N1755.html
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 33584347
I don't see any answers given yet
The reference to Dave Pawson's FAQ list has examples for CSV into XML, not the other way round

CSV is tricky, because a lot of the CSV importers don't support ful CSV standard.
Before going into the XSLT it is worth checking what your CSV importer supports, eg. is it Excel?

The spec for CSV more or less says the following

- if there is a comma in the data, put double quotes around the datafield
- if there are double quotes in the data and you need to escape comma's, make the double quotes double

so if this is your data
<field>a</field><field>b</field><field>c</field>
this would be the csv
a,b,c

if this is your data
<field>a</field><field>b,b</field><field>c</field>
this would be the csv
a,"b,b",c
allthough some importers would expect
a,"b,b",c

if this is your data
<field>a</field><field>b"b</field><field>c</field>
this would be the csv
a,b"b,c

if this is your data
<field>a"a</field><field>b,b</field><field>c</field>
this would be the csv
"a""a","b,b","c"

But you should make an example file first and see how your importer deals with them, because most importers are pretty weak in supporting full CSV spec

I have a question answered recently here where I expand more on CSV. I will try to find it
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 33584401
some references

http://en.wikipedia.org/wiki/Comma-separated_values
gives the explanation about the format

the spec can be found here
http://www.ietf.org/rfc/rfc4180.txt

and the accepted answer for this question has an XSLT that does most of the ground work for escaping
(allthough applied to the specific source XML)
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_26308972.html
0
 

Author Closing Comment

by:Blowfelt82
ID: 33660412
Thanks for the references and the comments, helped me work out how to resolve my problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question