Subject: Re: [xsl] efficiency with id() From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 3 Jul 2003 11:03:01 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] efficiency with id(), James Cummings | Thread | Re: [xsl] efficiency with id(), David Carlisle |
Re: [xsl] xpath confusion, David Carlisle | Date | Re: [xsl] efficiency with id(), David Carlisle |
Month |