Re: [xsl] translate apos in string

Subject: Re: [xsl] translate apos in string
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 16 Jan 2007 12:23:55 +0100
This is a FAQ.

Because of the nature of using strings in XPath/XSLT and the nature of XML and the way they deal with entities, your statement below will not compile. Since you use translate(), my guess is you use XSLT 1 (if not, you can escape an apostrophe by using a doubled apostrophe).

As long as you only want to remove apostrophes (and not also quotes), the following solution is the easiest (switching the quotes of the attribute to apostrophes, and the quotes inside the expressions to normal quotes):

<xsl:value-of select='translate($test, "&apos;&#xA;", "")' />

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl




Jimmy wrote:
I'm trying to get rid of the ' and the line feeds in my string but can't get it to work.

That's what I have so far:

<xsl:value-of select="
translate(translate(/node,'&#xA;',''),'&apos;', '&apos;')"/>


The first translation of line feeds works just fine, but I can't get rid of the apostrophe. The parser gives me an error because of the &apos. I tried different stuff but couldn't get the proper solution.


Anyone got a hint there?

Thanks
Jimmy

Current Thread