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

Re: counting characters in an XML document

Subject: Re: counting characters in an XML document
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 24 Oct 2001 17:12:19 -0400
count characters in a line
Tom:

Mike B. has already pointed out that this is more problematic than it may seem on the surface.

If you want to count the number of characters *just in text nodes*, you can use the XPath expression string-length(/) to get a count. (The root node, taken as a string, is the concatenation of all the text nodes in the document.) I am leaving aside complexities of counting Unicode combining characters together or separately, etc.: most (all) processors will just give a straight character count, I think.

Also, whitespace characters such as line feeds, extra space to indent elements, etc. will be counted unless you strip them with <xsl:strip-space elements="..."/>.

Counting the length of the text might be a useful alternative for your purposes to counting elements.

Cheers,
Wendell

At 03:10 PM 10/24/01, you wrote:
Hi,
Does anyone know how I can use XSL to count the number of characters in an
XML document. I want to process the XML so that, if there are less than a
certain amount of characters, a certain message gets printed. Another option
could be counting number of tags (elements)

any ideas out there?

Thanks,

Tom

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


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



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.