XSL: choosing another node if one is not available

APB

Usenet Archive
Joined
Nov 10, 2002
Messages
6
Reaction score
0
I am working on an XSL to transform RSS/RDF feeds into HTML

I have come across a bunch of feeds that only have a <description> for each <item> but no <title>.

In this event I would like to use the <description> node as if it where the <title> node. I tried something like the following fragment, but it doesn't change anything. How can I obtain what I require while keeping one single universal XSLT? Thanks!

<xsl:template match="item">
<xsl:variable name="item_link" select="link"/>
<xsl:variable name="item_descr" select="description"/>
<xsl:variable name="item_title" select="title"/>
<li >
<a href="{$item_link}" target="_blank" >
<xsl:if test="$item_title=''">
<xsl:value-of select="description" />
</xsl:if>
<xsl:value-of select="title"/>
</a>
<br /><div style="display:none"><xsl:value-of select="description" disable-output-escaping="yes" /></div> </li> </xsl:template>

Alex.
 

peterpeter

Usenet Archive
Joined
Feb 11, 2004
Messages
4
Reaction score
0
Hi.

I'm not sure, but if the <title> element doesn't exist at all, its value is rather invalid than an empty string. This would mean, that your comparison never will be true because there is no value to compare with. You have to test if the value exists anyway. Try the following change:

....
<xsl:if test="$item_title">
....

If you also want avoid empty strings, you have to combine both comparisons.

Bye
Peter
 

APB

Usenet Archive
Joined
Nov 10, 2002
Messages
6
Reaction score
0
Looks like I'm getting somewhere with this, thanks!

<xsl:if test="not($item_title)">

does the trick.

Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top