[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Calculate the average line length within variable nam

Subject: Calculate the average line length within variable name="lines" as="element()*" not including the last line
From: Alex Muir <alex.g.muir@xxxxxxxxx>
Date: Mon, 12 Apr 2010 09:42:09 +0000
 Calculate the average line length within variable  nam
Hi,

I'm trying to calculate the average line length in variable lines ,
not including the last line, where the new line is represented by a
placeholder '

I store each line in an element and capture it's length and text which
works fine.

 <xsl:variable name="lines" as="element()*">
      <xsl:analyze-string select="text()" regex="'">
        <xsl:non-matching-substring>
          <xsl:element name="line">
            <xsl:attribute name="length"
select="string-length(normalize-space(.))"/>
            <xsl:attribute name="text" select="."/>
          </xsl:element>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </xsl:variable>

I can get the average like so including the last line

<xsl:variable name="averageLineLength"
          select="round(avg($lines/@length))" as="xs:double"/>

I can get the last line length without error

<xsl:variable name="averageLineLength"
          select="round(avg($lines[last()]/@length))" as="xs:double"/>


However in the case where my number lines is greater than 2 <xsl:when
test="$numberLines ge 2"> I don't want to include the last line as
part of my count and was trying the following

<xsl:variable name="averageLineLength"
          select="round(avg($lines[last()]/preceding-sibling::node()/@length)
)"
as="xs:double"/>


Which gives me the error:

Description: An empty sequence is not allowed as the value of variable
$averageSpaceNormalizedLineLength


What am I doing wrong?

Thanks


--
Alex
https://sites.google.com/a/utg.edu.gm/alex

Some Good Music
http://sites.google.com/site/greigconteh/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.