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

Subject: [xsl] Re: Re: Measuring the (byte) size of an XSL output chain onthe fly
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 24 Jul 2003 00:07:51 +0200
Eric,

Of course my first attempt at it was idiotic, I shouldn't write anything at
midnight... but:

Your idea is great -- probably we could use a kind of an already existing
prettyprinter (must be the opposite to save space), which outputs just text
and feed it with the result of the transformation as kept in the
xsl:variable. Then it will produce just text -- and when captured in a
second xsl:variable we can get the exact length.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


"Eric van der Vlist" <vdv@xxxxxxxxxxxx> wrote in message
news:1058996171.1788.281.camel@xxxxxxxxxxx
> 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
>
>




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


Current Thread