Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: XSLT Programmer's Reference, 2nd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: XSLT Programmer's Reference, 2nd Edition
This is the forum to discuss the Wrox book XSLT: Programmer's Reference, 2nd Edition by Michael Kay; ISBN: 9780764543814
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT Programmer's Reference, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 20th, 2014, 12:04 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default escape double quote into two double quotes

I need to create a CSV file from some XML. I can use XSLT 2.0.

I am placing quotes around my fields as some of them contain commas.

But in some of my XML fields I have XML like this ->

<linkHtml href="#TRIALS">CLINICAL EFFICACY TRIALS</linkHtml>

I need to somehow escape each double quote into two double quotes or similar so that Excel will read the CSV file properly and not mess up all my columns.

This is the XSLT code that matches on the element.

<xsl:template match="hl7:linkHtml | linkHtml">
<a href="{@href}">
<xsl:apply-templates></xsl:apply-templates>
</a>
</xsl:template>

Does anyone have a suggestion on how to approach this?

Regards, John.
Reply With Quote
The Following User Says Thank You to JohnBampton For This Useful Post:
  #2 (permalink)  
Old August 20th, 2014, 01:01 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

I figured it out myself. The code was like this:

<xsl:character-map name="a">
<xsl:output-character character="&lt;" string="&lt;"/>
<xsl:output-character character="&gt;" string="&gt;"/>
</xsl:character-map>

<xsl:output omit-xml-declaration="yes" indent="no" encoding="UTF-16" use-character-maps="a"></xsl:output>


<xsl:template match="hl7:linkHtml | linkHtml">
<xsl:text>&lt;a</xsl:text>
<xsl:for-each select="attribute::*">
<xsl:text> </xsl:text>
<xsl:value-of select="name(.)"></xsl:value-of>
<xsl:text>=""</xsl:text>
<xsl:value-of select="."></xsl:value-of>
<xsl:text>""</xsl:text>
</xsl:for-each>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="serialize"/>
<xsl:text>&lt;/a</xsl:text>
<xsl:text>&gt;</xsl:text>
</xsl:template>
Reply With Quote
  #3 (permalink)  
Old August 20th, 2014, 03:37 AM
mhkay's Avatar
Wrox Author
Points: 18,176, Level: 58
Points: 18,176, Level: 58 Points: 18,176, Level: 58 Points: 18,176, Level: 58
Activity: 12%
Activity: 12% Activity: 12% Activity: 12%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,920
Thanks: 0
Thanked 277 Times in 272 Posts
Default

Why are you using the XML output method to generate CSV? If you used the text output method, you wouldn't need the character maps, because angle brackets in the result tree wouldn't be escaped. Add method="text" to your xsl:output.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
why extra double quote and dot ? help me ! sandeepgreaternoida BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 May 8th, 2009 03:18 PM
escape double quote inside JavaScript mister_mister XSLT 5 January 23rd, 2008 12:56 PM
escape character for double quotes Andy dg C# 2005 3 March 15th, 2007 10:51 PM
displaying single quotes and double quotes ren_123 Classic ASP Databases 2 February 22nd, 2006 01:17 PM
Double Quotes and Single Quotes Problem phungleon Classic ASP Basics 7 May 27th, 2004 01:44 PM



All times are GMT -4. The time now is 02:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.