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