This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: possible value-of return values
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] possible value-of return values
- From: tcn at melvaig dot co dot uk (Trevor Nash)
- Date: Mon, 30 Jul 2001 19:22:08 GMT
- Organization: Melvaig Software Engineering Limited
- References: <001401c11926$e1f3afa0$d7a8a8c0@monsterdaata.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
On Mon, 30 Jul 2001 14:38:52 -0400, you wrote:
>Hello,
>
>Given the following XML document:
><root>
><user name="Alex" password="Elephant" color=""/>
><user name="Reuter" password="Rhino"/>
></root>
>I was wondering if anyone knew the distinction in return values between:
><xsl:value-of select="/root/user[@name='Alex']/@color"/>
>And
><xsl:value-of select="/root/user[@name='Reuter']/@color"/>
>
>
>My guess is they would both be null, but I need to execute logic which
>hinges on whether the attribute exists and has a null value OR whether it
>exists at all.
>
Not 'null' but an empty string. Both are empty strings but for
different reasons: in the first case you are getting a node set
containing the attribute node, which when converted to a string gives
the value of the attribute, in the second you are getting an empty
node set which when converted to a string gives you "". But when
converted to a boolean a non-empty node-set gives you true, and an
empty one false. So:
<xsl:if test="/root/user[@name='Alex']/@color">
This is true
</xsl:if>
<xsl:if test="/root/user[@name='Reuter']/@color">
This is false
</xsl:if>
>Anything you got would be great.
>
>Thanks,
>
> Alex
>
Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email
Melvaig Software Engineering Limited
voice: +44 (0) 1445 771 271
email: tcn@melvaig.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list