xsl-list
[Top] [All Lists]

Re: Measure the length of an XML document in bytes

2005-08-04 06:35:06
Hi,
Tempore 14:49:54, die 08/04/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Khorasani, Houman 
<houman_khorasani(_at_)csgsystems(_dot_)com>:

Any ideas how to count the length of a document character by character?

You could obtain a roughly estimated value by performing a pseudo-serialization 
of the inut tree:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/">
        <xsl:variable name="doc">
                <xsl:apply-templates select="." mode="serialize"/>
        </xsl:variable>
        estimated size: <xsl:value-of select="string-length($doc)"/>
</xsl:template>

<xsl:template match="comment" mode="serialize">
<xsl:text/>&lt;!--<xsl:apply-templates mode="serialize"/>--&gt;<xsl:text/>
</xsl:template>

<xsl:template match="processing-instruction()" mode="serialize">
<xsl:text/>&lt;?<xsl:value-of select="name()"/>
<xsl:text> </xsl:text><xsl:value-of select="."/>?&gt;<xsl:text/>
</xsl:template>

<xsl:template match="*" mode="serialize">
<xsl:text/>&lt;<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="serialize"/>&gt;<xsl:text/>
<xsl:apply-templates mode="serialize"/>
<xsl:text/>&lt;/<xsl:value-of select="name()"/>&gt;<xsl:text/>
</xsl:template>

<xsl:template match="@*" mode="serialize">
<xsl:text> </xsl:text><xsl:value-of select="name()"/>
<xsl:text/>="<xsl:value-of select="."/>"<xsl:text/>
</xsl:template>

</xsl:stylesheet>


regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Spread the wiki (http://www.wikipedia.org)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--