I have an XSL that I use to render RSS feeds. I want to detect whether the <description>
element of an item starts with <![CDATA[
- if so, the <description>
content should not be rendered. If it doesn't start with <![CDATA[
then it can be rendered.
But I can't seem to match <![CDATA
.
Here's an example RSS feed:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="pretty-feed.xsl"?>
<rss version="2.0">
<channel>
<title>My Blog</title>
<link>http://example.com/</link>
<description>My Blog description</description>
<item>
<title>My Blog Post</title>
<link>http://example.com/2002/09/01/my-post/</link>
<description>Content of the post.</description>
</item>
</channel>
</rss>
And here's part of my pretty-feed.xsl
file, showing the relevant part:
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<xsl:for-each select="/rss/channel/item">
<xsl:if test="not(starts-with(normalize-space(description), '<![CDATA['))">
<p>
<xsl:value-of select="description" />
</p>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This always renders the <description>
, whatever it starts with. So I guess the <![CDATA[
isn't "seen" by the XSL as characters? Is there a way I can detect whether it exists or not?