• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsl:if test="..." testing for if node populated....

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to insert an article headline, body, and image; the content is uploaded via a CMS... but content will not always contain image, so: need to test for if image is present... how do I test for if a node is populated.. let's say node is "PHOTO_SMALL".... is this right way to do it?

<xsl:if test="PHOTO_SMALL!=''"><xsl:value-of select="PHOTO_SMALL" /></xsl:if>


thanks!!

Veronica
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that would work. But a shorter way is this:

<xsl:value-of select="PHOTO_SMALL" />

If there is no PHOTO_SMALL element under the context node, then the result of this is an empty string.

However if for example you wanted to put an <img href="PHOTO_SMALL"> element in the output only if there was a PHOTO_SMALL element to use, then you would need the <xsl:if> element.

Anyway, try it and see.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic