Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 19th, 2008, 10:27 AM
Authorized User
 
Join Date: Jul 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Issue in escaping comma from string in transforms

I have a problem in csv tranformation using xslt from xml.
The problem is the city string is having a comma inside like "huntington,ny" and when generated into a csv, its splitted into two cells and got messed up.
If anyone could let me know how to escape this comma from city and fit into a single cell of the csv file.

<xsl:value-of select="Info/city"/>
<xsl:value-of select="','"/>

Thanks in advance.

 
Old August 19th, 2008, 10:38 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's why CSV often puts quotes around fields. But then you have to escape the quote if the field has a quote as one of its characters. How do you wish to escape the comma?

--

Joe (Microsoft MVP - XML)
 
Old August 19th, 2008, 10:53 AM
Authorized User
 
Join Date: Jul 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

we don't have control over the source xml, but it will great if we can do something at the xslt to treat this field a little special by allowing to put quote or somenthing and at the output file should go with properly in a single field. thanks.

 
Old August 19th, 2008, 11:03 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't follow, can you show an example of the output you'd like if the field has a comma in it?

--

Joe (Microsoft MVP - XML)
 
Old August 19th, 2008, 12:49 PM
Authorized User
 
Join Date: Jul 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

output can be something like this will be fine:
user1,'huntington,ny',11717,US

 
Old August 20th, 2008, 03:25 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

So what wrong with the following:

<xsl:value-of select="Info/username"/>,"<xsl:value-of select="Info/city"/>",<xsl:value-of select="Info/zipcode"/>,<xsl:value-of select="Info/state"/>

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace the string has comma with spaces? kumiko Classic ASP Basics 3 January 10th, 2008 06:41 PM
Formatting string with comma arnabghosh SQL Server 2005 1 October 16th, 2007 01:38 AM
Word wrap in XSL that transforms to a text file suri_1811 XSLT 1 November 15th, 2006 03:59 PM
ASPUPLOAD issue: ="Invalid Class String"= Calverstine Classic ASP Basics 1 August 10th, 2005 05:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.