This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


Hello David,

That did the trick, thanks!

Thanks,
   Brian Young


-----Original Message-----
From: David Carlisle [mailto:davidc@nag.co.uk]
Sent: Wednesday, September 27, 2000 11:24 AM
To: xsl-list@mulberrytech.com
Subject: Re: How to search for <, >, etc. in a string?



> I have XML that contains some CDATA:
> 
> <string>
> 	<![CDATA[<u>Link containing a & character</u>]]>
> </string>


which is the same input tree to xsl as


<string>
	&lt;u&gt;Link containing a &amp; character&lt;/u&gt;
</string>




> I'd like to strip out the <u> and </u>, but only if they exist in the CDATA. >  To that end, I've used the string functions.  An example of this is:
> 
> <xsl:when test="starts-with($linkTextUnStripped, '<u>')">
> 	<xsl:value-of select="substring($linkTextUnStripped, 4)" />
> </xsl:when>

You didn't specify how you set the variable linkTextUnStripped
but unless it was defined via normalise-space() then
"4" is unlikely to be the right number, and starts-with is not going to
be true. As the fist four characters are
&#10;&#32;&#32;&#32;

The less than (&lt;) is the 10th character in the string, unless I mis
counted.

Why not use 


<xsl:when test="contains($linkTextUnStripped, '&lt;u&gt;')">
	<xsl:value-of select="
    substring-before(substring-after(, '&lt;u&gt;'), '&lt;/u&gt;') "/>
</xsl:when>

David


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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]