[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xsl-list
Subject:    Re: [xsl] XPath shorthand
From:       Ihe Onwuka <ihe.onwuka () googlemail ! com>
Date:       2012-09-19 7:51:28
Message-ID: CALfs7+w9EP-7xc9jp7DDTz0yAeUvwyB+znRMm69g1ZXe5h57Sg () mail ! gmail ! com
[Download RAW message or body]

On Tue, Aug 21, 2012 at 8:28 PM, Andrew Welch <andrew.j.welch@gmail.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@lists.mulberrytech.com>
--~--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic