RE: XPath 1.0: Literal with both ' and "?

This is a well-known limitation in the XPath 1.0 specification.

XPath 2.0 fixes it by allowing the delimiting quote to be doubled, so
you can write

'Tom said, "Why can''t I read?"'

In XPath 1.0, you can do it with concat():

concat("Tom said, ", '"', "Why can't I read?", '"')

There are unlikely to be any further errata published on XPath 1.0.
Apart from anything else, this is not an error in the spec, merely poor
language design.

Michael Kay



> -----Original Message-----
> From: www-xpath-comments-request@w3.org 
> [mailto:www-xpath-comments-request@w3.org] On Behalf Of Perry A. Caro
> Sent: 16 January 2004 22:30
> To: www-xpath-comments@w3.org
> Cc: caro
> Subject: XPath 1.0: Literal with both ' and "?
> 
> 
> 
> Production [29] of the XPath 1.0 spec says:
> 
> [29]    Literal    ::=    '"' [^"]* '"'  
>                           | "'" [^']* "'" 
> 
> Given that, how do I form a literal that has both ' and " in 
> it? For example, I want to search for an attribute whose 
> value is an excerpt from some dialog:
> 
> 	Tom said, "Why can't I read?"
> 
> In XML, this might be represented as:
> 
> 	<excerpt text='Tom said, "Why can&apos;t I read?"'/>
> 
> How would I form a predicate in XPath 1.0 that would match 
> the value of the text attribute?
> 
> I think this might be a bug in the specification, but I 
> didn't see any mention of it in the Errata.
> 
> Perry A. Caro
> Adobe Systems Incorporated
> 
> 

Received on Friday, 16 January 2004 18:32:02 UTC