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

Re: efficiency with id()

Subject: Re: efficiency with id()
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 3 Jul 2003 11:03:01 +0100
Re:  efficiency with id()
Hi James,

> Is it best to do something like:
> -----
> <xsl:template match="/">
>   <xsl:copy-of select="id($id)"/>
> </xsl:template
>
> <!-- and another empty template matching anything you don't want to display -->

If you have the first template, you don't need the second. The first
template says "copy the element with ID $id and that's it", so no
nodes other than the root node ever get templates applied to them.

> or is there a quicker way? Is key() quicker? The @id is in reality
> declared as type ID, so seems reasonable to use that. (This is for a
> quite large (well 2.5meg), file, which admittedly would probably be
> better just burst out into seperate files for each <p> element in
> this example.) Any suggestions appreciated.

Personally, I'd use a key rather than id(), but that's because I'm
paranoid about DTDs not being available during particular
transformations, so prefer the reliability of using a key. However, if
you're just copying a single paragraph, then doing:

  <xsl:copy-of select="foo[1]/bar[1]/blort[1]/p[@id = $id][1]" />

might be just as good or better because a well-designed processor
would know that it doesn't have to search through the entire document
for the relevant <p>, and it might save the processor from building a
table that it uses only once, which might save time.

As usual in efficiency questions, the best idea is to try it and see,
with representative XML and using the environment in which the
transformation is actually going to take place. And if you really need
an efficient way of extracting a single <p> element from a large
document, a SAX filter would be a lot quicker than an XSLT
transformation.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.