ASP Error: 70
Description: Permission denied
Source: Microsoft VBScript runtime error

[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: Mike Brown <mike@xxxxxxxx>
Date: Wed, 24 Oct 2001 13:59:54 -0600 (MDT)
xslt count characters
Tom Melkonian wrote:
> 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)

XSLT only operates on parsed documents, so you can't, without extension
functions, count characters in an unparsed document.

Parsing means decoding the bytes (if necessary) to Unicode characters and
then decoding the characters ("tags" and everything in between) to the
logical structures they imply: elements, attributes, character data,
processing instructions and sometimes comments, and making these available
to an application such as an XSLT processor. 

The XSLT processor will interpret the structures as a logical tree of
nodes according to the XPath data model (see the XPath spec). From within
XSLT you have access to these nodes.

So you can easily count element nodes:
<xsl:value-of select="count(//*)"/>

Or all nodes:
<xsl:value-of select="count(//node())"/>

But guessing at the original representation of the document as a string of
characters, when you all have to go on is the node tree, is impossible to 
do with any accuracy.

   - Mike
____________________________________________________________________________
  mike j. brown, fourthought.com  |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  personal: http://hyperreal.org/~mike/

 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.