Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL: choosing another node if one is not available

Reply
Thread Tools

XSL: choosing another node if one is not available

 
 
APB
Guest
Posts: n/a
 
      02-11-2004
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.
--
__________________________________________________ _________
a p bertolini

(www.webwarrior.org)


 
Reply With Quote
 
 
 
 
peterpeter
Guest
Posts: n/a
 
      02-12-2004
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
 
Reply With Quote
 
 
 
 
APB
Guest
Posts: n/a
 
      02-12-2004
Looks like I'm getting somewhere with this, thanks!

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

does the trick.

Alex.

--
__________________________________________________ _________
a p bertolini

(www.webwarrior.org)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find path from one tree node to another tree node Peter Mueller Java 6 01-13-2008 02:36 AM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
How to drag a sub-node to another node in TreeView? wolf ASP .Net 0 08-18-2004 11:51 PM
[HELP] Create a DOM using a node from another node yio@free.fr Java 0 07-16-2003 12:30 PM



Advertisments