Re: [xsl] Non Existent attribute, and other things.

Subject: Re: [xsl] Non Existent attribute, and other things.
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 12 Mar 2001 13:27:10 GMT
> 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


Current Thread