[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] XML file size from XSLT

Subject: RE: [xsl] XML file size from XSLT
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Fri, 9 Jan 2004 12:56:28 -0700

> From: Jiang, Peiyun [mailto:Peiyun.Jiang@xxxxxxxxxxxxxx]
> Sent: Friday, January 09, 2004 12:07 PM
> Subject: [xsl] XML file size from XSLT
> Is it possible to get the approximate XML file size from 
> XSLT? Is it posible
> to use some string functions to count the number of chars 
> under document
> element (though sounds terrible)?

You can't get a literal size of the file, because the XSLT processor doesn't
see a simple text file, but a tree of nodes.  However, you can use the XPath
function string-length() to get a character count of textual nodes.  Given
an XML input of

  <content>Some text</content>
  <content>Some other text</content>

The following XSLT stylesheet:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
  <xsl:strip-space elements="document"/>
  <xsl:template match="/">
    <xsl:value-of select="string-length(document)"/>

will output 24.  Note that xsl:strip-space is used to remove all whitespace
nodes within the <document> element--if you omit it, then the result from
the sample input will be 31 (three newlines and four spaces that indent the
<content> elements).  This in no way corresponds to the physical size of the
XML file on your disk, but this may suit your purposes.


| brian martinez                           brian.martinez@xxxxxxxxxxx |
| lead gui programmer                                    303.357.3548 |
| cheap tickets, part of trip network                fax 303.357.3380 |
| 6560 greenwood plaza blvd., suite 400           englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread