chekmate111
asked on
Remove Cdata from xslt output
In this file:
http://rss.wunderground.com/auto/rss_full/CO/Aurora.xml?units=both
You will see a Cdata section under <description>.
I would like to use all the <description> elements except that one. Can I omit Cdata sections?
This is what I have so far:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="channel">
<xsl:apply-templates select="item" />
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select="item" />
<font face="verdana" color="#CCCCCC" size="2" />
<b><xsl:value-of select="title" /></b><br />
<xsl:value-of select="description" />
<br /><br />
</xsl:template>
</xsl:stylesheet>
http://rss.wunderground.com/auto/rss_full/CO/Aurora.xml?units=both
You will see a Cdata section under <description>.
I would like to use all the <description> elements except that one. Can I omit Cdata sections?
This is what I have so far:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="channel">
<xsl:apply-templates select="item" />
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select="item" />
<font face="verdana" color="#CCCCCC" size="2" />
<b><xsl:value-of select="title" /></b><br />
<xsl:value-of select="description" />
<br /><br />
</xsl:template>
</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
joseph,
I don't think not(*) will work because the <img> you are refering to,
is inside the CDATA section and will not be accessed as a child node, but as a "<img ...." text node
if the existence of teh img pseudo tag is a possible trigger
you could use
description[contains(., '<img')]
which is similar to checking for "|"
Bottom line is
- if you can find a trigger inside the text that will tell you not to use that description (eg. teh img pseudo tag or a | or whatever)
you can use the contains() in the test
- if not you will have to preprocess the XML before the parser gets to it
cheers
Geert
I don't think not(*) will work because the <img> you are refering to,
is inside the CDATA section and will not be accessed as a child node, but as a "<img ...." text node
if the existence of teh img pseudo tag is a possible trigger
you could use
description[contains(., '<img')]
which is similar to checking for "|"
Bottom line is
- if you can find a trigger inside the text that will tell you not to use that description (eg. teh img pseudo tag or a | or whatever)
you can use the contains() in the test
- if not you will have to preprocess the XML before the parser gets to it
cheers
Geert
in your code that would mean
replace
<xsl:value-of select="description" />
with
<xsl:if test="not(contains(descrip tion, '<img'))">
<xsl:value-of select="description" />
</xsl:if>
cheers
Geert
replace
<xsl:value-of select="description" />
with
<xsl:if test="not(contains(descrip
<xsl:value-of select="description" />
</xsl:if>
cheers
Geert
if for one reason or another you would like the content of description, but not in its escaped form
you can do this
<xsl:value-of select="description" disable-output-escaping="y es"/>
you can do this
<xsl:value-of select="description" disable-output-escaping="y
ASKER
Okay, I think I understand now.
I would love to split the points between you two if possible. Would that be okay with you guys?
I would love to split the points between you two if possible. Would that be okay with you guys?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PS: if you don't need to do it in one pass, then you can use XSLT 2.0 both for preprocessing (regex) and processing (xslt), like Geert proposed.
ASKER
You could use xpath to work around it.
I see that the asker has added a suggestion and asks that to be accepted as the solution.
What the asker suggests is NOT a solution to the original question.
His solution requires parsing the XML to allow XPath to access to it, CDATA sections will be long gone then, as has been mentioned before.
The question has been answered correctly and extensively before.
So I DO object to this measure.
What the asker suggests is NOT a solution to the original question.
His solution requires parsing the XML to allow XPath to access to it, CDATA sections will be long gone then, as has been mentioned before.
The question has been answered correctly and extensively before.
So I DO object to this measure.
Force accepted.
modus_operandi
EE Moderator
modus_operandi
EE Moderator
ASKER
http://rss.wunderground.com/auto/rss_full/CO/Aurora.xml?units=both
as your file? The reason I ask is because I am not sure I understand the syntax of [not(*)].