Subject: Re: [xsl] XSLT: text()=''' From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 11 Jul 2003 15:20:34 +0100 |
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 ' entity. Can > anyone suggest what I'm doing wrong please? > > XSLT: > <xsl:template match="//subjectterm[text()='Employees' rights and > obligations']"> > <subjectterm>Employees rights</subjectterm> > </xsl:template> The ' and " 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 " and if you have an XML attribute like foo='...' then any ' within the value has to be escaped with '. You don't need to use ' in an attribute value delimited by ". In your example above, you can use ' or ' 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 ' and " 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()="Employees' rights and obligations"]" or: match='//subjectterm[text()="Employees' 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSLT: text()=''', Cole, Chris | Thread | Re: [xsl] XSLT: text()=''', David Carlisle |
Re: [xsl] XSL/XPath Dynamic sort ke, Fett Boba | Date | Re: [xsl] XSL/XPath Dynamic sort ke, David Carlisle |
Month |