This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Length of a variable?


> <xsl:variable name="colours" select="colour"/>
> 
> Further on in the stylesheet, there is to be a branch on whether
> $colours contains any colur elements or not. 

You are almost there.  You are setting $colours to a node-set containing
the colour elements which are the children of the context node.  You can
then get the number of elements in $colours with count($colours).

A mindset question, though: is it really necessary to store this in a
variable?  Not using a variable gets you out of having to test the
number of colours at some point where the variable would be in scope.

In general with XSL, you can frequently replace the use of a variable
with the direct access to the data that XPath gives you.  For example,
you might do:

 <xsl:if test="count(../paint/colour)">

depending on the context, of course.

 Steve


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]