Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL: testing for existance 1

Status
Not open for further replies.

Jawa

Programmer
Feb 21, 2002
74
US
How could I go about testing for the existance of a value in my XML?

say:

<person>
<name value=&quot;Peter&quot;>
<address>75 Hunts Street</address>
</name>
<name value=&quot;Andrew&quot;>
<address></address>
</name>
<name>
<address>45 Main</address>
</name>
</person>


For the above how could I go about using the for-each to only display on values but not empties?

Thank you!!!!




 
If the values were empty, nothing would be displayed anyway!

Otherwise, the way you can test if something exists would be something like this:

<xsl:if test=&quot;Address!=''&quot;>
<xsl:value-of select=&quot;Address&quot;/>
</xsl:if>

This would only display the value if it existed. Another way to check would be to use content-length i.e.

<xsl:if test=&quot;content-length(Address)>0&quot;>

Checks if the length of the content is greater than 0.

Hope this helps you! Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top