[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XPath shorthand

Subject: Re: [xsl] XPath shorthand
From: Ihe Onwuka <ihe.onwuka@xxxxxxxxxxxxxx>
Date: Wed, 19 Sep 2012 08:51:28 +0100

On Tue, Aug 21, 2012 at 8:28 PM, Andrew Welch <andrew.j.welch@xxxxxxxxx> 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()">

<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.

Current Thread