Subject: Re: [xsl] How to use xsl:key to make my XSLT program super-efficient? From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 12 Mar 2025 12:04:40 -0000 |
On Wed, 12 Mar 2025 at 11:50, Roger L Costello costello@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi Folks, > > I have a huge (1.2GB) XML document containing air navigation data. I need > to convert the XML document to another XML format, i.e., it is an > XML-to-XML translation task. > > Deep within the source XML document is an <ARPT> element that contains > <row> elements, one for each airport in the world: > > <Air_Navigation> > ... > <ARPT> > <row> > airport 1 data (bunch of child elements) > </row> > <row> > airport 2 data (bunch of child elements) > </row> > ... > </ARPT> > ... > </Air_Navigation> > > My XSLT needs to be super-efficient because the XML document is huge, and > I need to perform a lot of processing. > > When I think of "efficiency" what comes to mind is the xsl:key/key() pair. > > I need to iterate over each airport record, i.e., iterate over each <row> > element within the <ARPT> element. I figured that the following > xsl:key/key() pair will enable me to iterate efficiently: > > <xsl:key name="airports" match="ARPT/row" use="''"/> > > <xsl:for-each select="key('airports','')"> ... </xsl:for-each> > > Is that correct? Is that efficient? Will the loop execute super-fast? > If Michael doesn't reply saying the way to test efficiency is to time the code I'll be shocked:-) But no, I'd expect it to be slower. A key is (probably) a hash table that allows you to quickly access nodes based on some value, so it's an extension of referencing an element by id. But you need to traverse the document to build the hash table, and need to allocate the memory to store it. So if you are only going to traverse the nodes once, doing it first and building the table is not time well spent David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to use xsl:key to mak, Martin Honnen martin | Thread | Re: [xsl] How to use xsl:key to mak, Graydon graydon@xxxx |
Re: [xsl] How to use xsl:key to mak, Martin Honnen martin | Date | Re: [xsl] How to use xsl:key to mak, Graydon graydon@xxxx |
Month |