[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Antwort: RE: bad programming for speedup?

Subject: Re: Antwort: RE: bad programming for speedup?
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Tue, 24 Jul 2007 08:53:02 -0400
Re:  Antwort: RE:  bad programming for speedup?
Hi,

Is the OP sure that the elements wrapping the rows cannot be determined
beforehand and have templates set up for those? If so, from what I can
see, all that is needed is:

<xsl:template match="tbl-type1 | tbl-type2 | tbl-type-etc">
  <table>
    <xsl:apply-templates/>
  </table>
</xsl:template>

<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:appy-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>

best,
-Rob


On Tue, 2007-07-24 at 14:46 +0200, Abel Braaksma wrote:
> Hi Christoph,
> 
> Have you tried the other suggestions? Mainly Andrew's method (or mine 
> even, if the below does what I think it does).
> 
> Please allow me to make some suggestions on your code below:
> 
> 
> 
> christoph.naber@xxxxxxxxxxxxxxxxxxx wrote:
> >   
> >       <xsl:template match="/">
> >                 <xsl:apply-templates />
> >         </xsl:template>
> >   
> >
> 
> This is not necessary in this particular template. However, you may feel 
> that having a specific entry point in your code is a matter of good 
> practice (many do).
> 
> >  
> >         <xsl:template match="*">
> >                 <xsl:copy>
> >                         <xsl:copy-of select="@*" />
> >                         <xsl:apply-templates select="*" /> 
> >                 </xsl:copy>
> >         </xsl:template>
> >   
> 
> To save yourself some keystrokes (also further on), you can as well 
> write the above as follows:
> 
> <xsl:template match="node() | @*">
>     <xsl:copy>
>        <xsl:appy-templates select="node() | @*" />
>     </xsl:copy>
> </xsl:template>
> 
> In addition, this way (using node() instead of *), text nodes, 
> processing instructions etc are also processed by your copy template.
> 
> >  
> >         <xsl:template match="row[position() = 1 or 
> > preceding-sibling::*[name() != 'row' and position() = 1]]" >
> >                 <table>
> >                         <xsl:apply-templates select="." mode="more2come"/>
> >                 </table>
> >         </xsl:template>
> >   
> 
> Take a close look at the way Andrew coded this same principle. Also, 
> consider an earlier remark by Justin about *not* using name() to compare 
> nodes. Use self::row instead. This will help you when you are attempting 
> sources that contain namespaces.
> 
> >         <xsl:template match="row" mode="more2come">
> >                 <xsl:copy>
> >                         <xsl:copy-of select="@*" />
> >   
> 
> The line above (xsl:copy-of) can be removed if you follow the remark 
> made above about the copy template.
> 
> >                         <xsl:apply-templates select="*" /> 
> >   
> 
> And this should really read:
> 
>    <xsl:apply-template select="node() | @*" />
> 
> to make it all work well.
> 
> >                 </xsl:copy>
> >                 <xsl:if test="following-sibling::*[name() = 'row' and 
> > position() = 1]">
> >                         <xsl:apply-templates 
> > select="following-sibling::row[position() = 1]" mode="more2come" />
> >                 </xsl:if>
> >   
> 
> Whenever you find yourself making an xsl:if with a node test, followed 
> by an xsl:apply-templates with (largely) the same call, it is most 
> likely that you can easily write it in one statement and make it clearer 
> for you and fellow coders. Note that xsl:apply-templates does nothing 
> when the selection contains an empty set, making the xsl:if from 
> imperative programming style largely redundant.
> 
> See the code of Andrew for an example.
> 
> 
> >         </xsl:template>
> >  
> >         <xsl:template match="row" >
> >         </xsl:template>
> 
> Using the approach of Andrew, you do not need this delete-template, 
> saving on keystrokes again ;)
> 
> If you want it simple and fast, I believe the approach with keys is 
> quicker, but not necessarily so of course. In addition, since all you do 
> is plain copying and no further processing, it is likely that the 
> <xsl:copy-of> constructor from my example will work the fastest 
> nonetheless. But I haven't seen your source, so I couldn't tell (and 
> with an optimizing processor it may matter zero after all).
> 
> Cheers & happy coding ;)
> 
> -- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.