xsl-list
[Top] [All Lists]

RE: XML file size from XSLT

2004-01-09 12:56:28
From: Jiang, Peiyun 
[mailto:Peiyun(_dot_)Jiang(_at_)nrc-cnrc(_dot_)gc(_dot_)ca]
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

<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(_dot_)martinez(_at_)cendant(_dot_)com |
| 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



<Prev in Thread] Current Thread [Next in Thread>