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

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

Dimitre,

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"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

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

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

   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"/>
   </xsl:if>
 </xsl:template>

</xsl:stylesheet>

Which gives:
   Length of output is: 174
&lt;nums&gt;
  &lt;num&gt;01&lt;num/&gt;
  &lt;num&gt;02&lt;num/&gt;
  &lt;num&gt;03&lt;num/&gt;
  &lt;num&gt;04&lt;num/&gt;
  &lt;num&gt;05&lt;num/&gt;
  &lt;num&gt;06&lt;num/&gt;
  &lt;num&gt;07&lt;num/&gt;
  &lt;num&gt;08&lt;num/&gt;
  &lt;num&gt;09&lt;num/&gt;
  &lt;num&gt;10&lt;num/&gt;
&lt;nums/&gt;

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 http://wap.xmlfr.org 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!

Eric
-- 
Read me on XMLhack.
                                      http://xmlhack.com/author.php?id=8
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
(W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema
------------------------------------------------------------------------


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



Current Thread
Keywords