RE: [xsl] How to select for ' in XPATH?

Subject: RE: [xsl] How to select for ' in XPATH?
From: "Mario Madunic" <Mario_Madunic@xxxxxxxxxxxx>
Date: Wed, 5 Aug 2009 12:43:32 -0500
I don't know if this will help but...

I've not done this in XPath per se but needed to use the translate function to
translate an apostrophe to what I can't remember. The trick was to create a
variable of the apostrophe and reference the variable in the translate

<xsl:variable name="apos">'</xsl:variable>

Marijan (Mario) Madunic
Publishing Specialist
New Flyer Industries
(204) 934 8815

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: Wednesday, August 05, 2009 12:20 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] How to select for &apos; in XPATH?

I don't really know anything about the shell that you are using and any
escaping or unescaping that it is doing, so it's a bit hard to tell. The
general rule in XPath 2.0 is that if a string literal is enclosed in single
quotes, an apostrophe should be represented as a pair of adjacent


Michael Kay

> -----Original Message-----
> From: Hermann Stamm-Wilbrandt [mailto:STAMMW@xxxxxxxxxx]
> Sent: 05 August 2009 18:04
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] How to select for &apos; in XPATH?
> Hello,
> I tried to select for special characters with XPATH below.
> While I succeeded for some I am unable to select for the
> &apos; character (') and got an error message.
> Any hint how this can be done?
> $ xmlsh
> $ cat tst.html
> <html><body>
> <p>lt and gt: &lt; &gt; </p>
> <p>apos and quot: &apos; &quot; </p>
> </body></html>
> $ tidy -q -xml tst.html;
> <html>
>   <body>
>     <p>lt and gt: &lt; &gt;</p>
>     <p>apos and quot: ' "</p>
>   </body>
> </html>
> $ xpath "/*/*/*[contains(normalize-space(.),'<')]" <tst.html
> <p>lt and gt: &lt; &gt; </p> $ xpath
> "/*/*/*[contains(normalize-space(.),'>')]" <tst.html <p>lt
> and gt: &lt; &gt; </p> $ xpath
> "/*/*/*[contains(normalize-space(.),'\"')]" <tst.html <p>apos
> and quot: ' " </p> $ xpath
> "/*/*/*[contains(normalize-space(.),'\'')]" <tst.html
> Exception running: xpath
> net.sf.saxon.s9api.SaxonApiException: XPath syntax error at char 34 in
> {...ontains(normalize-space(.),...}:
>     Unmatched quote in expression
> $
> Mit besten Gruessen / Best wishes,
> Hermann Stamm-Wilbrandt
> Developer, XML Compiler
> WebSphere DataPower SOA Appliances
> ----------------------------------------------------------------------
> IBM Deutschland Research & Development GmbH Vorsitzender des
> Aufsichtsrats: Martin Jetter
> Geschaeftsfuehrung: Erich Baier
> Sitz der Gesellschaft: Boeblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294

Please consider the environment before printing this e-mail.

CONFIDENTIALITY STATEMENT: This communication (and  any and all information or
material transmitted with this communication) is confidential, may be
privileged and is intended only for the use of the intended recipient. If you
are not the intended recipient, any review, retransmission, circulation,
distribution, reproduction, conversion to hard copy, copying or other use of
this communication, information or material is strictly prohibited and may be
illegal. If you received this communication in error or if it is forwarded to
you without the express authorization of New Flyer, please notify us
immediately by telephone or by return email and permanently delete the
communication, information and material from any computer, disk drive,
diskette or other storage device or media. Thank you.

Current Thread