Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT performance issue

Status
Not open for further replies.

JontyMC

Programmer
Nov 26, 2001
1,276
GB
Is it better to specify a node directly?

i.e. is:

Code:
/firstlevel/secondlevel/somenode

better (or quicker) than saying:

Code:
//somenode

Thanks,

Jon
 
I think it'd would be better, if you just writw the node as //somenode. That allows some mistakes and changes and it goes straight the address you wanted.
 
I am thinking more in terms of performance and good practice though. Does the XSLT processor find a node more quickly with the first method or is it indistinguishable?
 
Consider this simplefied xml-document:
Code:
<library>
 <books>
  <book>
   <writer>Lowry</writer>
  </book>
 </books>
 <cds>
  <cd>
   <musician>Leadbelly</musician>
  </cd>
 </cds>
</library>
The x-path expression "//musician" forces the parser to check if a musician-node exitst in:
- library
- books
- (every) book
- writer
- cds
- (every) cd
The x-path expression "library/cds/cd/musician" forces the parser to check if a musician-node exitst in:
- (every) library/cds/cd
You bet there is a difference in performance, depending on the number of books you have.

As for good practice: suppose the xml is a bit more complicated:
Code:
<library>
 <books>
  <books_about_musicians>
   <book>
    <writer>Lowry</writer>
    <musician>Robert Johnson</musician>
   </book>
  </books_about_musicians>
 </books>
 <cds>
  <cd>
   <musician>Leadbelly</musician>
  </cd>
 </cds>
</library>
The x-path expression "//musician" might get you some unexpected results.

Conclusion: be as specific as you can.





 
XPath isn't terribly efficient anyway -- it (usually) does a straight linear search, so if your document gets over 1000 "records" you'll see search time skyrocket.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top