Re: [xsl] counting characters in an XML document

Subject: Re: [xsl] counting characters in an XML document
From: ronald heller <ronald@xxxxxxxxxxx>
Date: Mon, 05 Nov 2001 10:18:18 +0100
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