Re: [xsl] Measure the length of an XML document in bytes

Subject: Re: [xsl] Measure the length of an XML document in bytes
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 04 Aug 2005 15:35:06 +0200
Hi,
Tempore 14:49:54, die 08/04/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Khorasani, Houman <houman_khorasani@xxxxxxxxxxxxxx>:

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)

Current Thread