Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2008, 11:07 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default Speed Transformation

Hi,

I am using XSLT 1.0 and IE6

I have written the XSLT below and it works fine. However, when the XML has lots of RowGrp elements then it becomes quite slow to transform.

The difficulty that I am having is to find a way to speed it up. I think there could be two problems with my XSLT:

1 - Recursion in the ColGrp Template mode="header"

<xsl:for-each select="//ColGrp[count(ancestor::ColGrp)=$depth]">

2 - Also, when I am in the Col Template I have to go back to the measures element for each Col

<xsl:for-each select="//Col">
  <xsl:apply-templates select="//Measures">
    <xsl:with-param name="pos" select="position()" />
  </xsl:apply-templates>
</xsl:for-each>

I would appreciate if someone could sched some light. I have read Jeni's XSLT pages (key and grouping) but have not found any posts or example similar to mine.

Cheers

C
===========================
XML
<Reports>
<Report xmlns="">
  <Measures>
    <Measure idx="1" heading="Total Pages" />
    <Measure idx="2" heading="Cost" />
  </Measures>
  <Columns>
    <ColGrp heading="Quarter">
      <ColGrp heading="2003">
        <Col heading="Quarter 1" />
        <Col heading="Quarter 2" />
        <Col heading="Quarter 3" />
        <Col heading="Quarter 4" />
      </ColGrp>
      <ColGrp heading="2004">
        <Col heading="Quarter 1" />
        <Col heading="Quarter 2" />
        <Col heading="Quarter 3" />
        <Col heading="Quarter 4" />
      </ColGrp>
    </ColGrp>

    <ColGrp>
      <ColGrp>
        <Col heading="Total" />
      </ColGrp>
    </ColGrp>
  </Columns>
</Report>
</Reports>

==============================

XSLT

<xsl:param name="axisHeads" select="'false'" />

  <xsl:variable name="msrs">
    <xsl:choose>
      <xsl:when test="//Measure">
        <xsl:value-of select="count(//Measure)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="1"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

 <xsl:template match="Reports">
    <xsl:apply-templates select="Report"></xsl:apply-templates>
  </xsl:template>

  <xsl:template match="Report" >

      <div id="g1" style="position: absolute; top: 0px; left: 0px; width: 400px; height: 12px">
        <table class="grdTop" border="0" cellspacing="1" cellpadding="0">
          <tbody>
            <xsl:apply-templates select="Columns" />
          </tbody>
        </table>
      </div>
   </xsl:template>

  <xsl:template match="Columns">
    <xsl:apply-templates select="ColGrp[1]" mode="Header">

      <xsl:with-param name="depth">
        <xsl:choose>
          <xsl:when test="$axisHeads='true'">
            <xsl:value-of select="0"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="1"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:with-param>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="ColGrp" mode="Header">
    <xsl:param name="depth" />
    <tr>

      <xsl:for-each select="//ColGrp[count(ancestor::ColGrp)=$depth]">
          <td colspan="{count(.//Col)*$msrs}" align="center" style="overflow:none">
          <nobr>
            <div>
              <xsl:value-of select="@heading"/>
            </div>
          </nobr>
        </td>
      </xsl:for-each>
    </tr>
    <xsl:choose>
      <xsl:when test="ColGrp">
        <xsl:apply-templates select="ColGrp[1]" mode="Header">
          <xsl:with-param name="depth" select="$depth+1" />
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="Col[1]" mode="colHead" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="Col" mode="colHead">
    <tr>
      <xsl:for-each select="ancestor::Columns//Col">
        <td colspan="{$msrs}" valign="top" align="center" style="overflow:none">
          <nobr>

            <div>
              <xsl:value-of select="@heading"/>
            </div>
          </nobr>
        </td>
      </xsl:for-each>
    </tr>
    <tr valign="bottom">
      <xsl:for-each select="//Col">
        <xsl:apply-templates select="//Measures">
          <xsl:with-param name="pos" select="position()" />
        </xsl:apply-templates>
      </xsl:for-each>
    </tr>
  </xsl:template>

  <xsl:template match="//Measures">
    <xsl:param name="pos" />
    <xsl:for-each select="Measure">
      <xsl:variable name="mPos">
        <xsl:value-of select="position()" />
      </xsl:variable>
      <td align="center">
        <nobr>
          <div class="action" style="width:90px; overflow:none" onclick="sortFullGrid({$mPos}, {$pos}, '{@class}')">
            <xsl:value-of select="@heading"/>
          </div>
        </nobr>
      </td>
    </xsl:for-each>
  </xsl:template>
 
Old February 29th, 2008, 03:56 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi,

Since no one has replied to my post, I would like to try to clarify the problem I am having.

I need want to build a nested heading Rows/Columns (<TR> and <TD>). The output should look like this for the 2003 heading:

                          2003
    Quarter 1 Quarter 2 Quarter 3 Quarter 4
Total Pages Cost Total Pages Cost Total Pages Cost Total Pages Cost

<ColGrp heading="Quarter">
  <ColGrp heading="2003">
    <Col heading="Quarter 1" />
    <Col heading="Quarter 2" />
    <Col heading="Quarter 3" />
    <Col heading="Quarter 4" />
  </ColGrp>
</ColGrp>

I use the xpath below to get me to the inner most ColGrp (parent of Col elements).

Normally $depth = 1
//ColGrp[count(ancestor::ColGrp)=$depth]

//ColGrp[count(ancestor::ColGrp)=1]

So, I go to the ancestor:ColGrp whose depth = 1

This will produce the first <TD>s

2003 2004

Then all the Col elements will produce the second row with all the <TD>s

Quarter 1 Quarter 2 Quarter 3 Quarter 4

And lastly, for each Col element I have to go back to the Measure elements to produce the final Row which will be the same for all the Col elements

Total Pages Cost Total Pages Cost Total Pages Cost Total Pages Cost

Therefore, this is the output I get with my XSLT but it is too slow for big xml docs.

                                2003
    Quarter 1 Quarter 2 Quarter 3 Quarter 4
Total Pages Cost Total Pages Cost Total Pages Cost To


Is it possible to to improve the speed of the transformation?

I have posted the same question to another forum but apparently it might be too difficult to improve the speed of my XSLT since I only received one reply.

However, if someone has experienced speed problems with their xslt, I would like to kindly ask that you shed some light about my problem. Please let me know if my explanation is not clear enough so that I can try and make it clearer.

Cheers

C





Similar Threads
Thread Thread Starter Forum Replies Last Post
speed umeshtheone VB Databases Basics 2 May 21st, 2007 04:12 PM
Speed up macro EricB123 Excel VBA 1 April 30th, 2007 11:39 AM
speed up macro Pindacko Excel VBA 1 April 27th, 2006 01:41 PM
how to speed up the page? p2pMember ASP.NET 1.0 and 1.1 Professional 5 March 30th, 2006 03:12 PM
Speed kilika SQL Server 2000 10 July 1st, 2003 06:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.