notGeek
notGeek

Reputation: 1528

RSS to XHTML using XSLT - How to remove strange characters?

I'm using XSLT to transform RSS files in XHTML. In order to create a link I use this block of code:

<!-- language: lang-xml -->
<xsl:for-each select="channel/item">
   <h3><a href="{link}"><xsl:value-of select="title"/></a></h3>
   <xsl:value-of select="description"/>
</xsl:for-each>

But the result comes with some unwanted characters:

<!-- language: lang-html -->
<h3><a href="%0A                http://site.com/page.htm%0A            ">

What am I doing wrong? Thanks in advance for your help.

Upvotes: 0

Views: 321

Answers (1)

hcayless
hcayless

Reputation: 1046

It looks like the source has URLEncoded line feeds and some whitespace in it. Leading and trailing whitespace can be stripping using the normalize-space() function. The other stuff may be trickier, depending on how regular it is, and which version of XSLT you're using. If the URLs always end in "%0A ", you could do something like:

substring-before(substring-after(link, 'http'), "%")

This will only work all the time if your URLs are never going to have URLEncoded data in them (which might not be a safe assumption). If you're using XSLT 2.0, something like:

normalize-space(replace(link, '%0A', ''))

might work better.

Upvotes: 2

Related Questions