xsl-list
[Top] [All Lists]

Re: Measure the length of an XML document in bytes

2005-08-04 21:13:08
Hi Houman,
   I just finished writing a Java extension function which determines
file size in bytes (as reported by Windows). Below is the Java code,
XSLT stylesheet and Xalan command line. With this stylesheet, we can
pass the file name from command line.

Java file
-----------
package MyPackage;

import java.io.File;

public class Utility {

  public static long getFileSize(String filename) {
    File file = new File(filename);
    return file.length();
  }
}

XSLT stylesheet
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
                xmlns:my-class="xalan://MyPackage.Utility" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        
<xsl:output method="text" />

<xsl:param name="filename" />

<xsl:template match="/">
  File Size : <xsl:value-of select="my-class:getFileSize($filename)" /> bytes
</xsl:template>
        
</xsl:stylesheet>

Xalan Command Line
------------------------------
C:\xml\xsleg\xslt>java org.apache.xalan.xslt.Process -in file_size.xsl -xsl file
_size.xsl -PARAM filename node.xml

  File Size : 111 bytes

But sorry, if this is not what you want. Just thought of sharing the code.  

Regards,
Mukul

On 8/4/05, Khorasani, Houman <houman_khorasani(_at_)csgsystems(_dot_)com> wrote:
Hi Mukul,

Interesting idea. However I am stuck between two middlewares.  I have to
use plain XSLT's. There won't be any java involved.

Actually, I read the customers req. and it says lengths of the
characters are good enough. So I don't need to know the length in bytes.

So if I would use string-length() like this

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

I would get just the length of the first value.
I wish I could use it like that:

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

But this is not possible.
Any ideas how to count the length of a document character by character?

Many thanks,
Houman

--~------------------------------------------------------------------
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>
--~--