This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Non Existent attribute, and other things.
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Non Existent attribute, and other things.
- From: David Carlisle <davidc at nag dot co dot uk>
- Date: Mon, 12 Mar 2001 13:27:10 GMT
- References: <191E23677373D411BFB900D0B7A7BA28025C1A@mail.vbninternal.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
> Well I would have thought that a possibly non-existent
> attribute is 0 or not would be
why 0 of all things? How would you distinguish it from a value of 0?
> So I end up doing...
> count(@value) = 0 or not(number(@value))
count(@value) = 0
is just a long (and slow) way of doing
@value
in either case the expression is true just if the node set is non empty.
I'm not sure why you are coercing @value to a number and then to a
boolean in the second part of th etest, what exactly are you testing
for?
test="@value"
tests if the value attribute is used. Is that all you need?
> key('Ps', $name)[count(.|$Ps) = count($Ps)]
> ...as I really don't understand it.
key('Ps', $name)
returns a node set of all nodes which have the value $name for the key
Ps
[count(.|$Ps) = count($Ps)]
removes all of those nodes that are not in the node set $Ps.
as if the node (.) is in the set $Ps then the set (. | $Ps) will be
equal to $Ps and so have the same count. If the node . is not in the set
then the union (. | $Ps) will have one extra element, so a different
count.
> There must be a more succinct method.
In general no. If you cared about succinctnes, you shouldn't be using
XML but in that particular example:
<xsl:variable name="shorter">
<xsl:choose>
<xsl:when test="@short">
<xsl:value-of select="@short"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<menu name="{$name}">
is
<menu name="{@short|@name[not(@short)]}">
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list