[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Measure the length of an XML document in bytes

Subject: Re: Measure the length of an XML document in bytes
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 04 Aug 2005 15:35:06 +0200
bytes to text
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

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.