xsl-list
[Top] [All Lists]

RE: Printing a value if an attribute does not exist

2004-08-24 01:43:23
In 2.0 you simply do:

<xsl:value-of select="(region[(_at_)name='VA'], '0.0')[1]"/>

In 1.0 it's a bit more long-winded:

<xsl:choose>
  <xsl:when test="region[(_at_)name='VA']">
     <xsl:value-of select="region[(_at_)name='VA']"/>
  </xsl:when>
  <xsl:otherwise>0.0</xsl:otherwise>
</xsl:choose>

Michael Kay


-----Original Message-----
From: michael(_dot_)s(_dot_)eberhart(_at_)verizon(_dot_)com 
[mailto:michael(_dot_)s(_dot_)eberhart(_at_)verizon(_dot_)com] 
Sent: 24 August 2004 04:04
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Printing a value if an attribute does not exist





How do you check for the existence of an attribute?

<TIER>
   <REGION NAME="CT">89</REGION>
   <REGION NAME="MD">135</REGION>
</TIER>

What I want to say is:

If region[(_at_)name="VA"] exists
   print value of region[(_at_)name="VA"]
else
   print "0.0"

It is also possible that there will be no REGION elements

<TIER>
</TIER>

I would still want to say:

If region[(_at_)name="VA"] exists
   print value of region[(_at_)name="VA"]
else
   print "0.0"

Thanks

Mike




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>