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

RE: XML file size from XSLT

Subject: RE: XML file size from XSLT
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Fri, 9 Jan 2004 12:56:28 -0700
xslt file size
> From: Jiang, Peiyun [mailto:Peiyun.Jiang@xxxxxxxxxxxxxx]
> Sent: Friday, January 09, 2004 12:07 PM
> Subject:  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

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

The following XSLT stylesheet:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="document"/>
  <xsl:template match="/">
    <xsl:value-of select="string-length(document)"/>
  </xsl:template>
</xsl:stylesheet>

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.

hth,
b.

| 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

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.