Impossible to tell without measuring it, really. My instinct would be to avoid using the parent axis and "//", I would tend to write
 
saxon:distinct($x/section/section[item[string(@pk)]]/@class
 
(I think that string(@pk) in a boolean context gives the same answer as string-length(@pk). string-length() is a surprisingly expensive operation because of the need to search for Unicode surrogate pairs).
 
Michael Kay


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Andre Cusson
Sent: 19 May 2004 19:08
To: saxon-help@lists.sourceforge.net
Subject: [saxon] back axis efficiency

Hi,

Is there a difference (ex: in performance), and of what order, when working on a node-set like a variable loaded from a large xml file with a structure that looks like :
                <xsl:variable name="x">
                        <section id='all'>
                                <section class='a'>
                                        <item pk="1"/>
                                        <item alpha="z"/>
                                        <item pk="2"/>
                                        ...
                                        
<item pk="n"/>
                                </section>
                                <section class='b'>
                                        <item pk="1"/>
                                        <item alpha="z"/>
                                        <item pk="2"/>
                                        ...
                                        
<item pk="n"/>
                                </section>
                                ...
                                
<section class='n'>
                                        <item pk="1"/>
                                        <item alpha="z"/>
                                        <item pk="2"/>
                                        ...
                                        
<item pk="n"/>
                                </section>
                        </section>
                </xsl:variable>

let's say that we are looking for unique sub-section classes for items that meet a certain condition, would it be better to use
something like :
                <xsl:for-each select="saxon:distinct($x//*[string-length(@pk)]/parent::*[1]/@class)">
                        ...
                
</xsl:for-each">

or something like :
                <xsl:for-each select="saxon:distinct($x//*[./*[string-length(@pk)]]/@class)">
                        ...
                
</xsl:for-each>

or even something like :
                <xsl:for-each select="saxon:distinct($x/section/section[./*[string-length(@pk)]]/@class)">
                        ...
                
</xsl:for-each>

Which would be better, which would be more efficient ?

Thank you.
Cheers,
Andre