Re: [xsl] counting specific nodes

Subject: Re: [xsl] counting specific nodes
From: Mukul Gandhi <mukulgw3@xxxxxxxxx>
Date: Wed, 15 Oct 2003 18:58:20 -0700 (PDT)
Here is another solution --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:variable name="startpos">1</xsl:variable>
<xsl:template match="/vs">
   <xsl:variable name="dots">
      <xsl:for-each select="ve">
	<xsl:variable name="val"
	<xsl:if test="($val = $startpos) or ($val &gt;
	    <xsl:call-template name="countdots">	     
<xsl:with-param name="stringparam" select="@pos"/>
	      <xsl:with-param name="noofdots" select="0"/>
   Answer - <xsl:value-of
select="count(xalan:nodeset($dots)/a)" />
<xsl:template name="countdots">
  <xsl:param name="stringparam"/>
  <xsl:param name="noofdots"/>
  <xsl:variable name="sbst"
select="substring-after($stringparam, '.')"/>
  <xsl:if test="$sbst != '' ">
     <xsl:call-template name="countdots">
	<xsl:with-param name="stringparam" select="$sbst"/>
	<xsl:with-param name="noofdots" select="$noofdots +
  <xsl:if test="$sbst = '' ">
     <xsl:if test="$noofdots = 3">


At the begining of XSL, a varibale is declared to
mention the starting position; <xsl:variable

The XSL uses recursion to find the count of the
desired nodes. The above XSL creates a tag <a/> each
time it encounters a node in original XML having 3
dots (whose position is, on or after the "startpos"
value node). A variable "dots" ( declared as --
<xsl:variable name="dots"> )holds these <a/> tags
(which is a RTF -- result tree fragment). 

I convert the RTF into a nodeset, and calculate the
count of <a/> tags, *which is the answer*.


--- james walker <jameswalkerandy@xxxxxxxxxxx> wrote:
> given the xml
> <vs>
> <ve pos="1"></ve>
> <ve pos="1.1"></ve>
> <ve pos="1.1.1"></ve>
> <ve pos=""></ve>
> <ve pos=""></ve>
> <ve pos=""></ve>
> <ve pos"1.2"></ve>
> <ve pos="1.2.1"></ve>
> <<ve pos=""></ve>
> <ve pos="2"></ve>
> <ve pos="2.1"></ve>
> <ve pos="2.1.1"></ve>
> <ve pos=""></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= 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 ( ,
> Get Hotmail on your mobile phone
>  XSL-List info and archive: 

Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

 XSL-List info and archive:

Current Thread