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

Subject: [xsl] Re: Measuring the (byte) size of an XSL output chain on the fly
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 23 Jul 2003 23:24:25 +0200
This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </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>


when applied on this source.xml:

<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>

produces the wanted result:

   Length of output is: 51
<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Neil Smith" <neil@xxxxxxxxxxxxxxx> wrote in message
news:5.2.0.9.0.20030723215624.00ac32a8@xxxxxxxxxxxxxxxxxxxx
> Hi all -
>
> Run into an interesting problem which I hope somebody might have a few
> ideas about. I don't remember anything like this being discussed or
> documented. I'll be checking the wapforum and related sites in the
meantime.
>
> I am planning to transform some existing content into WML (wireless
markup)
> from a sequential XML source using XSLT (rather than DOM). The WML browser
> targets have limitations on the size of content which can be delivered,
> about 1500-1800 bytes uncompressed.
>
> I would like to retain the simplicity of doing this transformation using
an
> XSL stylesheet. However, I am not aware of any functions which can
> determine the output result size, in bytes, of a set of nodes. This is not
> a question about counting the input bytes, rather I want to determine if I
> can count the number of bytes in a result set as it is transformed.
>
> I envisage using a simple for-each loop, and checking before each
iteration
> if the result size exceeds the limiting value I put into a param in the
> stylesheet. If the result size is within a certain range of the limit, I
> would close the WML 'deck' and exit the stylesheet.
>
> So - has anybody got a good idea how I could do this ?
>
> Thanks in advance -
> Regards - Neil Smith.
>
>
>  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