xsl-list
[Top] [All Lists]

Re: [xsl] XPath shorthand

2012-09-19 02:51:40
On Tue, Aug 21, 2012 at 8:28 PM, Andrew Welch 
<andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> wrote:
In the end I went with

<xsl:key name="desired_fields"
match="m__id[1]|m__name[1]|m__path[1]|m__enabled[1]"
use="local-name()"/>

and

following-sibling::*[key('desired_fields',local-name())]

Why do that?


Because then all my end-user has to do if he wants to change the
fields being retrieved is add (or subtract) the relevant element name
from the match pattern.

..in which case:

<xsl:variable name="names" select="('m__id', 'm__name',
'm__path'....)" as="xs:string+"/>

with

following-sibling::*[local-name() = $names]

is the same but doesn't require the key, however you should really
take into account namespaces.


I suggested that the key solution may perform better because of the
number of general comparison entailed in the variable solution and was
invited to do a comparison. I don't have the volume of data (the file
is only 278k) but the number of items in the general comparison
entailed in the variable version has now risen to 30. So

using the variable version I benchmarked 1000 executions at an average of 125ms.

the keyed version

<xsl:variable name="this" as="node()" select="doc('')"/
<xsl:key name="desiredFields" match="this:desiredFields/*" use="local-name()"/>

<xsl:variable name="this:desiredFields" as="element()">
       <this:desiredFields>
         <product/><m__id/>........<productThumbnail/>
       </this:desiredFields>
    </xsl:variable>

<xsl:if 
test="following-sibling::*[key('desiredFields',local-name(),$this)]">,</xsl:if>

benchmarked 1000 executions at an average of 115ms.

Given the relatively file size, I would expect the advantage  to be
more marked as both the volume of the file  and the number of
comparison items increases.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [xsl] XPath shorthand, Ihe Onwuka <=