xsl-list
[Top] [All Lists]

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

2003-07-23 14:24:25
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(_at_)fresh-toast(_dot_)com> wrote in message
news:5(_dot_)2(_dot_)0(_dot_)9(_dot_)0(_dot_)20030723215624(_dot_)00ac32a8(_at_)pop(_dot_)freeserve(_dot_)net(_dot_)(_dot_)(_dot_)
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



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