[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Are xsl:key's best going into the future?
Hi Robert, > In fact, if you want to get the incredible performance gains from > XSLTC, they: [ Xalan's XSLTC team - > http://xml.apache.org/xalan-j/xsltc/xsltc_performance.html ] warn > that you should not use keys. > > Should keys be avoided? Actually, what that document says is that keys shouldn't be used *in patterns*. The example they give is: <xsl:template match="key('key-name', 'some-value')"> ... </xsl:template> Here, the template matches nodes that have the value 'some-value' according to the key 'key-name'. Assuming that the key is simply using the id attribute of elements: <xsl:key name="key-name" match="*" use="@id" /> The equivalent key-lesss way to express such a pattern is something like: <xsl:template match="node()[@id = 'some-value']"> ... </xsl:template> As you can see from the preceding performance tip on the same page, using predicates within patterns is a bad idea for good performance with XSLTC as well. The reason that both of these patterns are discouraged is because they are type-less matches. From their description, with both keys and the predicates, XSLTC can't quickly work out what kind of nodes could be matched by the pattern, so it has to look through the whole document to work it out. This use of keys to match nodes with patterns is very different from using keys to *select* nodes with an expression. There's nothing on the XSLTC performance page that indicates that keys shouldn't be used to select nodes, so I don't see any reason not to use them in that way. For example: <xsl:apply-templates select="key('some-key', 'some-value')" /> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|