[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: ronald heller <ronald@xxxxxxxxxxx>
Date: Mon, 05 Nov 2001 10:18:18 +0100
xsl count characters in string
With a match on "/" you select the root of your document so to speak, that is not the same as your root element.
with the <xsl:value-of select="string-length(child::*[1])"/> You say that you want the string-length of the returned concatenated string of your first root element.
I don't think you need the [1] for if wellformed XML, your xml only has one root element.


So the following would suffice:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="1.0">

    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
      <xsl:value-of select="string-length(*)"/>
    </xsl:template>

</xsl:stylesheet>

cheers,

RH

At 08:38 AM 11/5/01 +0000, you wrote:
The following appears to work:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="1.0">

    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
      <xsl:value-of select="string-length(child::*[1])"/>
    </xsl:template>

</xsl:stylesheet>

///Peter


=======



That solution confuses me - I would have expected descendants to work, rather than child::*[1]. <xsl:value-of select="string-length(descendants)"/>


Can somebody comment on what is happening in this line?


Thanks

Robert Stuart


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.