XSL: choosing another node if one is not available

Discussion in 'XML' started by APB, Feb 11, 2004.

  1. APB

    APB Guest

    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)
     
    APB, Feb 11, 2004
    #1
    1. Advertising

  2. APB

    peterpeter Guest

    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
     
    peterpeter, Feb 12, 2004
    #2
    1. Advertising

  3. APB

    APB Guest

    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)
     
    APB, Feb 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wolf
    Replies:
    0
    Views:
    553
  2. Replies:
    0
    Views:
    1,462
  3. CB
    Replies:
    1
    Views:
    592
    Johannes Koch
    Oct 2, 2003
  4. Tjerk Wolterink
    Replies:
    2
    Views:
    1,436
    Dimitre Novatchev
    Aug 24, 2006
  5. Peter Mueller
    Replies:
    6
    Views:
    4,570
    Stefan Ram
    Jan 13, 2008
Loading...

Share This Page