 |
| 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
|
|
|
|

October 1st, 2009, 08:00 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 1st, 2009, 08:10 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

October 1st, 2009, 08:15 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 1st, 2009, 08:18 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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$ ','~',','),'$','''')"/>
|
|

October 1st, 2009, 08:22 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

October 1st, 2009, 08:22 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tired this but giving following exception
TransformerException: Expected ,, but found:''
|
|

October 1st, 2009, 08:57 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
If you want to replace a dollar symbol with a single quote then use e.g.
Code:
<xsl:value-of select="translate(foo, '$', "'")"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

October 1st, 2009, 07:05 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|
 |