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

Re: XSLT: text()='''

Subject: Re: XSLT: text()='''
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 11 Jul 2003 15:20:34 +0100
apos
Hi Chris,

> As part of my stylesheet I was replacing a few terms using the
> following construct, but I appear to be having a problem with this
> particular string replacement as it contains an &apos; entity. Can
> anyone suggest what I'm doing wrong please?
>
> XSLT:
>   <xsl:template match="//subjectterm[text()='Employees&apos; rights and
> obligations']">
>     <subjectterm>Employees rights</subjectterm>
>   </xsl:template>

The &apos; and &quot; escapes are XML escapes that you have to use
within attribute values that are delimited by ' and " respectively. In
other words, if you have an XML attribute like foo="..." then any "
within the value has to be escaped with &quot; and if you have an XML
attribute like foo='...' then any ' within the value has to be escaped
with &apos;.

You don't need to use &apos; in an attribute value delimited by ". In
your example above, you can use ' or &apos; and the effect will be the
same.

When the attribute value is reported to an application (such as an
XSLT processor) by an XML parser, the &apos; and &quot; escapes are
converted into the relevant characters. In the above example, the
attribute value reported to the XSLT processor is:

  //subjectterm[text()='Employees' rights and obligations']

This is an XPath, but it's not a legal XPath because the ' within the
string literal is being interpreted as closing the string literal. The
XSLT processor is reporting an error because it can't parse the
attribute value.

To make the XPath legal, it has to look like:

  //subjectterm[text()="Employees' rights and obligations"]

In other words, the string literal has to be delimited by "s so that
the ' within the string isn't interpreted as the end of the string
literal.

If you put that into an XML document as an attribute value, then you
have to escape either the ' or the " depending on what delimiter you
use for the attribute. So you should use either:

  match="//subjectterm[text()=&quot;Employees' rights and obligations&quot;]"

or:

  match='//subjectterm[text()="Employees&apos; rights and obligations"]'

(In XPath 2.0, you can use '' in a string literal delimited by 's to
indicate a ' within the string literal, and similarly you can use ""
within a string literal delimited by "s to indicate a ".)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.