xsl-list
[Top] [All Lists]

RE: How do I get a SUM of the string-length of all child nodes ??

2005-05-27 02:17:58
In XSLT 1.0 the sum() function can only sum the string values of nodes, it
can't sum a set of computed numbers. This means your options are

(a) a two-phase transformation: first create a tree in which the computed
numbers are represented as attributes (typically), then sum over these
attributes

(b) a recursive template to compute the sum

In 2.0, like many things, it's much easier:

    sum(child::node()/string-length())

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: Bovy, Stephen J [mailto:STEPHEN(_dot_)Bovy(_at_)ca(_dot_)com] 
Sent: 27 May 2005 07:36
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How do I get a SUM of the string-length of all 
child nodes ??

I am not sure how to do this:

here is what I have which is obviously incorrect:

<xsl:template match="/*/*/*" >                                        
  <xsl:param name="rcnt" />                                           
  <xsl:choose>                                                        
  <xsl:when test="position()=1">                                      
    <xsl:variable name="csum" select="sum(string-length(.))"/>        
rsizes <xsl:value-of select="$rcnt"/> =<xsl:value-of select="$csum"/>;
  </xsl:when>                                                         
  <xsl:otherwise>                                                     
  bt('<td align="center"> ');                                         
  bt('<xsl:value-of select="."/> ');                                  
  bt('</td> ');                                                       
  </xsl:otherwise>                                                    
  </xsl:choose>                                                       
</xsl:template>                                                       

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--