Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 October 1st, 2009, 08:00 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to create string with quots

Hi All

I want to convert following string

$TEST$~$Test$~$TEST$ to 'TEST','Test','TEST'

I tried with translate function but its not working
<xsl:value-of select="translate(translate('$TEST$~$Test$~$TEST$ ','~',','),'$',''')"/>

# I am using xsl version="1.0"

# In Xsl , I am creating SQL query and i need this string in this format to pass to query

- Thanks Dishant
 
Old October 1st, 2009, 08:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well when you say 'its not working' what error do you get?

I tried running this in Kernow - a very good UI for testing XSLT, and it gave me a lovely message that enabled me to identify the error immediately. "Unmatched quote in expression". Therefore it was clear that I had the wrong number of quote symbols in the select expression.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 1st, 2009, 08:15 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sam,

Sam it is giving error because, i am trying to replase $ with ' but its throwing exception as parser is expecting one more quote.

<xsl:value-of select="translate(translate('$TEST$~$Test$~$TEST$ ','~',','),'$',''')"/>

Can u please tell how can i convert $ to ' (single quote) so that i can get single quote in string


- Thanks Dishant
 
Old October 1st, 2009, 08:18 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You just need to 'escape' the single quote (like you would in SQL) by putting another quote in front of it.

<xsl:value-of select="translate(translate('$TEST$~$Test$~$TEST$ ','~',','),'$','''')"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 1st, 2009, 08:22 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think Sam's suggestion for escaping single quotes by doubling them is XPath 2.0 only.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 1st, 2009, 08:22 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tired this but giving following exception

TransformerException: Expected ,, but found:''
 
Old October 1st, 2009, 08:57 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you want to replace a dollar symbol with a single quote then use e.g.
Code:
<xsl:value-of select="translate(foo, '$', &quot;'&quot;)"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 1st, 2009, 07:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XPath 2.0, the symbol used to delimit the string literal can be escaped by doubling it.

In either XPath 1.0 or 2.0, the symbol used to delimit the attribute value can be escaped using an XML character reference such as &_quot; (sans underscore).

Under either version, I find a useful technique is to use variables:

Code:
<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="translate(., '~', $apos)"/>
Michael Kay
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create one string from multiple fields paul20091968 Access VBA 17 August 3rd, 2007 09:52 AM
create one string from various records paul20091968 Access VBA 1 January 4th, 2007 04:18 PM
how to create a secure connection string... [email protected] ASP.NET 1.0 and 1.1 Professional 3 May 18th, 2006 05:51 AM
create string from For Each loop dhborchardt Classic ASP Databases 3 March 17th, 2004 01:18 PM
How to create a string from XML Island in HTML? chandima Javascript How-To 2 October 10th, 2003 02:08 PM





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