RE: How to search for <, >, etc. in a string?

Subject: RE: How to search for <, >, etc. in a string?
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Wed, 27 Sep 2000 17:37:21 +0100
> I have XML that contains some CDATA:
> 
> <string>
> 	<![CDATA[<u>Link containing a & character</u>]]>
> </string>
> 
> I'd like to strip out the <u> and </u>,...
> 
> <xsl:when test="starts-with($linkTextUnStripped, '<u>')">
> 
> The problem is the use of '<' and '>' in the second parameter 
> of the starts-with function.  I tried replacing them with 
> &lt; and &gt; but I believe that it is then literally looking 
> for '&' followed by 'l' by 't' by ';' and soforth.
>
Remember that CDATA and &lt; are all processed by the XML parser before the
XSLT processor gets a look in. So the string that the XSLT processor sees is

<u>Link containing a & character</u>

and the string that you want to look for is

<u>

So you need to write a string that the XSLT processor will see as <u>, and
you can do this by writing &lt;u&gt; in your source stylesheet.

The more likely source of your problem is the "starts-with" Your example
doesn't start with <u>, it starts with white space. The fact that the white
space is outside the CDATA section is irrelevant. Use normalize-space() to
remove the white space.

Mike Kay
 


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


Current Thread