xsl-list
[Top] [All Lists]

Re: [xsl] Slow XSLT

2008-03-14 16:59:39
Hi Manfred,

I have tried your latest sample XSLT and I have to
confess that I was really impressed. It is nearly
creating the table the way I need. 

In my previous post to you I said that I was using 4
<DIV> tags and 4 <TABLE> tags to build my GRID. 

However, if I am able to build everything using only
one table then I can try to use javascript to
transform this table into a GRID.... Woow, that would
be great.

This is still the problem with your sample XSLT:

1 - The row headings need to include the  parent
RowGrp headings. So it should look something like this
for the xml you included in your last post. Please
note that the first TD in the first row needs to have
the colspan based on the RowGrp - Row count and
rowspan based on the colGrp - Coll

+------------+----------+
|                       |
|                       |
|                       |
|                       |       
+------------+----------+
|            | A        |
+            +----------+
|  Name 1    | Other    |       
+            +----------+
|            | Another  |       
+------------+----------+
|            | Totals   |       
+------------+----------+


However, this has to be dynamic like the ColGrp
because I can have many levels of RowGrp. Example:

<Rows>
    <RowGrp heading="Full Name">
      <RowGrp heading="Name 1">
        <Row heading="A">

+------------+----------+--------+
|                                |  
|                                |
|                                |
|                                |       
+------------+----------+--------+
|            |          | A      |
+            + Name 1   +---------
|  Full Name |          | B      |
+            +----------+---------
|            | Name 2   | V      |
+------------+----------+---------
|            |          | Totals |
+------------+----------+---------

XML WITH MULTIPLE LEVELS OF ROWGRP
_________________________________


<?xml version="1.0" encoding="UTF-8" ?>
<Report>
  <Measures>
    <Measure idx="1" heading="Total Pages"/>
    <Measure idx="2" heading="Cost"/>
  </Measures>
  <Columns>
    <ColGrp heading="Year">
      <Col heading="2003"/>
      <Col heading="2004"/>
    </ColGrp>
  </Columns>
  <Rows>
    <RowGrp heading="Full Name">
      <RowGrp heading="Name 1">
        <Row heading="A">
          <Cell>
            <Msr idx="1" val="1" class="num1"/>
            <Msr idx="2" val="2840" class="cur1"/>
          </Cell>
          <Cell />
        </Row>
        <Row heading="B">
          <Cell>
            <Msr idx="1" val="1" class="num1"/>
            <Msr idx="2" val="2840" class="cur1"/>
          </Cell>
          <Cell />
        </Row>
      </RowGrp>
      <RowGrp heading="Name 2">
        <Row heading="V">
          <Cell />
          <Cell>
            <Msr idx="1" val="" class="num1"/>
            <Msr idx="2" val="" class="cur1"/>
          </Cell>
        </Row>
      </RowGrp>
    </RowGrp>
    <RowGrp heading="">
      <RowGrp heading="">
        <Row heading="Totals">
          <Cell>
            <Msr idx="1" val="4" class="num1"/>
            <Msr idx="2" val="2840" class="cur1"/>
          </Cell>
          <Cell>
            <Msr idx="1" val="4" class="num1"/>
            <Msr idx="2" val="55555" class="cur1"/>
          </Cell>
        </Row>
      </RowGrp>
    </RowGrp>
  </Rows>
</Report>


Cheers

C   


--- Manfred Staudinger <manfred(_dot_)staudinger(_at_)gmail(_dot_)com>
wrote:

On 14/03/2008, Michael Kay <mike(_at_)saxonica(_dot_)com>
wrote:
A lot has already been said and many suggestions
have already
 > been made in this thread to speed up the
processing of your
 > stylesheet, but since your stylesheet is rather
 > straightforward I doubt if any of the
suggestions really
 > speed up the processing.


I agree, these are all things that might give you
1% improvement. The only
 other thing I can suggest is looking at the
format-number() calls. I've
 known that be really slow on some
implementations. Try taking it out and
 seeing if it makes any difference.

I would like to propose to move the formating to the
css as much as
possible (that means all what is implemented by the
browsers you want
to support - this is a lot but OT on this list).
Begin your
measurements with the stylesheet below and observe
carefully any
changes when you add "string-formating". I use SAXON
6.5.5 with the -t
switch to get the timings. I've changed a few
things, if you have
questions don't hesitate to ask.

Manfred

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<!--
java -jar D:\Programme\Saxon6\saxon.jar -t slow0.xml
sslow2.xsl
-->
<xsl:param name="axisHeads" select="'true'"/>
<xsl:output indent="yes"/>

<xsl:variable name="msrs"
select="count(/Reports/Report/Measures/Measure)"/>

<xsl:template match="/">
      <html>
      <body>
              <table border="1">
              <tbody>
                      <xsl:choose>
                              <xsl:when test="$axisHeads = 'true'">
                                      <xsl:call-template name="apply-set">
                                              <xsl:with-param name="set"
select="Reports/Report/Columns/*"/>
                                      </xsl:call-template>
                              </xsl:when>
                              <xsl:otherwise>
                                      <xsl:call-template name="apply-set">
                                              <xsl:with-param name="set"
select="Reports/Report/Columns/*/*"/>
                                      </xsl:call-template>
                              </xsl:otherwise>
                      </xsl:choose>
                      <xsl:apply-templates
select="Reports/Report/Rows/*/*"/>
              </tbody>
              </table>
      </body>
      </html>
</xsl:template>

<xsl:template match="Row">
      <tr>
              <xsl:if test="$axisHeads = 'true'">
                      <th><xsl:value-of select="@heading"/></th>
              </xsl:if>
              <xsl:apply-templates/>
      </tr>
</xsl:template>
<xsl:template match="Cell">
      <xsl:apply-templates/>
</xsl:template>
<xsl:template match="Msr">
      <td><xsl:value-of select="@val"/></td>
</xsl:template>
<xsl:template match="Cell[not(*)]">
      <xsl:for-each select="/Report/Measures/Measure">
              <td/>
      </xsl:for-each>
</xsl:template>
<xsl:template match="text()"/>

<xsl:template name="apply-set">
      <xsl:param name="set"/>
      <tr>
              <xsl:if test="$axisHeads = 'true'">
                      <th/>
              </xsl:if>
              <xsl:apply-templates select="$set"/>
      </tr>
      <xsl:choose>
              <xsl:when test="$set/*">
                      <xsl:call-template name="apply-set">
                              <xsl:with-param name="set" select="$set/*"/>
                      </xsl:call-template>
              </xsl:when>
              <xsl:otherwise>
                      <tr valign="bottom">
                              <xsl:if test="$axisHeads = 'true'">
                                      <th/>
                              </xsl:if>
                              <xsl:for-each select="$set">
                                      <xsl:apply-templates
select="/Reports/Report/Measures/*">
                                              <xsl:with-param name="pos"
select="position()"/>
                                      </xsl:apply-templates>
                              </xsl:for-each>
                      </tr>
              </xsl:otherwise>
      </xsl:choose>
</xsl:template>

<xsl:template match="ColGrp">
      <th colspan="{$msrs*count(.//Col)}">
              <div><xsl:value-of select="@heading"/></div>
      </th>
</xsl:template>
<xsl:template match="Col">
      <th colspan="{$msrs}">
              <div><xsl:value-of select="@heading"/></div>
      </th>
</xsl:template>
<xsl:template match="Measure">
      <xsl:param name="pos" />
      <th>
              <div onclick="sortFullGrid({position()}, {$pos},
'')">
                      <xsl:value-of select="@heading"/>
              </div>
      </th>
</xsl:template>
</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="UTF-8" ?>
<Reports>
  <Report>
   <Measures>
     <Measure idx="1" heading="Total Pages"/>
     <Measure idx="2" heading="Cost"/>
   </Measures>
   <Columns>
     <ColGrp heading="Year">
       <Col heading="2003"/>
       <Col heading="2004"/>
     </ColGrp>
   </Columns>
   <Rows>
     <RowGrp heading="Name 1">
       <Row heading="A">
         <Cell/>
         <Cell>
           <Msr idx="1" val="42.00"/>
           <Msr idx="2" val="64230"/>
         </Cell>
       </Row>
       <Row heading="Other">
         <Cell/>
         <Cell>
           <Msr idx="1" val="36.00"/>
           <Msr idx="2" val="35820"/>
         </Cell>
       </Row>
       <Row heading="Another">
         <Cell>
           <Msr idx="1" val="14.20"/>
           <Msr idx="2" val="128030"/>
         </Cell>
         <Cell/>
       </Row>
     </RowGrp>
     <RowGrp heading="">
       <Row heading="Totals">
         <Cell>
           <Msr idx="1" val="14.20"/>
           <Msr idx="2" val="128030.00"/>
         </Cell>
         <Cell>
           <Msr idx="1" val="78.00"/>
           <Msr idx="2" val="100050.00"/>
         </Cell>
       </Row>
     </RowGrp>
   </Rows>




      ___________________________________________________________ 
Rise to the challenge for Sport Relief with Yahoo! For Good  

http://uk.promotions.yahoo.com/forgood/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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