xsl-list
[Top] [All Lists]

Re: counting specific nodes

2003-10-15 14:14:26
James,

the cheapest way to do this would be to count the length of each '@pos'.  If 
you can guarantee that there is only a single digit between each dot then a 
simple statement such as:

<xsl:variable name="rowspan" select="count(//ve/@pos[string-length(.) = 
7])"/>

would do the trick.  Another option would be:

<xsl:variable name="rowspan" 
select="count(//ve/@pos[string-length(substring-after(.,'.')) &gt;= 4])"/>

but if you are going to add additional function calls you might as well just 
do the following:

<xsl:variable name="rowspan" 
select="count(//ve/@pos[string-length(translate(.,'0123456789','')) = 3])"/>

the above strips out all the numbers leaving only the dots.  then a simple 
string-length test will tell you how many dots are left.

NOTE: changing your context node will allow you to decide which node to 
start your test with.

Best regards,

M.


----- Original Message ----- 
From: "james walker" <jameswalkerandy(_at_)hotmail(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, October 15, 2003 5:23 AM
Subject: [xsl] counting specific nodes


given the xml
<vs>
<ve pos="1"></ve>
<ve pos="1.1"></ve>
<ve pos="1.1.1"></ve>
<ve pos="1.1.1.1"></ve>
<ve pos="1.1.1.2"></ve>
<ve pos="1.1.1.3"></ve>
<ve pos"1.2"></ve>
<ve pos="1.2.1"></ve>
<<ve pos="1.2.1.1"></ve>
<ve pos="2"></ve>
<ve pos="2.1"></ve>
<ve pos="2.1.1"></ve>
<ve pos="2.1.1.1"></ve>
</vs>

and given that i am starting on a node with pos=1 (or 2 or 3....), how do 
i
count the nodes which have position with 3 dots only (e.g. pos=1.1.2.1?) 
and
start with the current node position. I came up with something like this:

<xsl:variable name="rowspan" select="count(ve[starts-with(@position,
current()/@position) and contains(...........)])" />
e.g. for position 1, it should be 4 (1.1.1.1 , 1.1.1.2, 1.1.1.3, 1.2.1.1)

_________________________________________________________________
Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile


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



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



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