Re: [xsl] Re: Measuring the (byte) size of an XSL output chain on the fly

Subject: Re: [xsl] Re: Measuring the (byte) size of an XSL output chain on the fly
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: 23 Jul 2003 23:36:11 +0200

On Wed, 2003-07-23 at 23:24, Dimitre Novatchev wrote:
> This transformation:
> when applied on this source.xml:


> produces the wanted result:
>    Length of output is: 51

Depends what you call length :-)

Shouldn't it be 175?

vdv@delleric:~/repros/libxslt$ wc -c length.xml
    175 length.xml

In the case of a WML deck, I think that you'll want to count the markup
too and to do so, you'd need to simulate a formating, for instance (not
dealing with attributes and namespaces):

<xsl:stylesheet version="1.0"

 <xsl:output omit-xml-declaration="yes"/>

  <xsl:template match="@*">
      <xsl:apply-templates select="@* | node()"/>
  <xsl:template match="*">
    <xsl:value-of select="name()"/>
    <xsl:apply-templates select="@* | node()"/>
    <xsl:value-of select="name()"/>

 <xsl:template match="/">
   <xsl:variable name="vResult">

   Length of output is: <xsl:text/>
   <xsl:value-of select="concat(string-length($vResult), '&#xA;')"/>

   <xsl:if test="string-length($vResult) &lt;= 1800">
     <xsl:copy-of select="$vResult"/>


Which gives:
   Length of output is: 174

I don't think you can get a very accurate estimation except if you can
know exactly how the output method will behave.

I had the same problem for and have solved this by
writing an extension function (for XT) which estimates the output. I
realize now that I could have used an adaptation of your stylesheet to
get a close result!

Read me on XMLhack.
Eric van der Vlist  
(W3C) XML Schema ISBN:0-596-00252-1

 XSL-List info and archive:

Current Thread