• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this effient ?

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am testing my application for exectution speed. I want to speed up my application by applying best practices in XSL.

I have a code like this,

<xsl:template name="resultResults">
<xsl:apply-templates select="//AAAA/BBB/CCC"/>
</xsl:template>

<xsl:template match="CCC">
<tr align="left">

</tr>
</xsl:template>

I simply want to traverse through CCC. I have heard and seen in tutorials that it is a good practice to use another template instead of a for each loop. So i have used another template to omit that for each loop. Although i have used a template i have accessed tht node like "//AAAA/BBB/CCC". So does it make sense? I want to know whether it will speed up my program.
Thank you.
[ December 07, 2007: Message edited by: Dilshan Edirisuriya ]
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That XPath expression starts with "//" and that means that the entire tree will have to be searched, starting at the root, to find nodes matching it. So if there is another way to express the requirements that doesn't require searching the entire tree, then that's an inefficient expression. But if it's the only way to express the requirements then the question of efficiency doesn't arise.

You didn't post any examples of your XML so we can't tell what the correct answer is.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so is there another way to do that task? Consider these types of situations,

<xsl:template name="NAME">
<xsl:for-each select="//AAA/BBB/CCC">

</xsl:for-each>
</xsl:template>

I have traverse through the root node. So it is not efficiecnt. How do i overcome that situation? By applying a template how can i acchieve the most efficient scenario?
Thank you
 
Paul Clapham
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't say that at all. I said that if there is a better way to do it then it's inefficient. But that may not be the case. It entirely depends on the XML document you are transforming. And using a template versus xsl:for-each has nothing at all to do with that.

You won't be able to know what is efficient and what is not until you know how XSLT works. Right now you don't. Personally I think you are wasting your time with this efficiency fetish. I think you would be better off learning XSLT properly instead of trying to discern rules like "X is more efficient than Y" which are often false and often lead to badly-written programs.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Paul
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic