[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Translating "("

Subject: Re: Translating "("
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 15 Nov 2004 12:36:03 GMT
translate normalize space
  I need translate special characters like "(", ")" etc in <ln:term>.

  <xsl:variable name="val" select="translate(normalize-space(ln:term),
  '&#39;&#160;/&#40;&#41;,&#34;""', '_')" />

  Unfortunately Saxon throws an exception at this line, because of
  resolving the character entities...


There's nothing special about ( in strings, you could just use ( to
denote those. and &#39; are not entity references but character
references (which are expanded at a different time)

You didn't show the error message you got, although it's unlikely to
have been from saxon, your quoted line is not well formed XML (It has a
two literal " characters inside a " delimited attribute value) so should
have been rejected by the XML parser before XSLT processing starts.

 <xsl:variable name="val" select="translate(normalize-space(ln:term),
                                 ^
  '&#39;&#160;/&#40;&#41;,&#34;""', '_')" />
                               ^^       ^

Getting ' and " into an Xpath string is a FAQ )and the faq for this list
will have an entry for it but you can not have a string literal that
contains both ' and " You appear to want to have the Xpath string

 '<nbsp>/(),"

You can have ' in a "-delimited string and " in a 'delimited string but
you can't have both in the same literal so you need to concat them
together eg

concat("'&#160;/()",'"')

Your translate function just had a string of length 1 so that's goint to
replace the first character  ' by _ and discard the rest, is that what
you want? assuming so:

You need

translate(normalize-space(ln:term),
   concat("'&#160;/()",'"')
   '_')

now to get that expression into a select attrbute. As far as XML is
concerned it's all just an opaque string, that has three " and five '
so if you are using " to delimit the attrinute you need to &quot; the
occurrences of " in the attribute value

select="translate(normalize-space(ln:term),
   concat(&quot;'&#160;/()&quot;,'&quot;')
   '_')"

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.