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

Re: [xsl] Theory question about keys (no code)


Subject: Re: [xsl] Theory question about keys (no code)
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 6 Aug 2012 14:15:33 -0700

> I believe that any decent (meaning with sensible optimization)  XSLT
> processor only builds an index for a specific XML document on the
> first actual call of the key() function -- do note that even if a
> reference to the key() function is statically present in the code,
> nothing guarantees that the key() function would be ever called.

Also, if the key() function is actually called, how could the XSLT
processor know in advance what the current XML document could be at
the time of the actual call? If this is unknown and the processor has
built in advanc an index for document X, it may happen that the
current XML document, at the time the key() function is called, is
document Y -- so a lot of effort/time would have been wasted in vain
for the premature construction of index for document X.

Another ancertainty: there may be more than one key definitions, and
the key-name argument to the key() function is a string (not a QName),
which means that the key-name may be contained in a
variable/parameter. In this case there is no way to know statically
which of the many possible keys will be referenced (if at all) at run
time.

Cheers,
Dimitre



On Mon, Aug 6, 2012 at 2:06 PM, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
>> My question is:  when is the associative array built?  Is it built entirely in the beginning,
>> as the source document is first read into memory?  Or is it built incrementally, as each
>> template is matched during transformation?
>
> The W3C specification leaves this open to implementors.
>
> I believe that any decent (meaning with sensible optimization)  XSLT
> processor only builds an index for a specific XML document on the
> first actual call of the key() function -- do note that even if a
> reference to the key() function is statically present in the code,
> nothing guarantees that the key() function would be ever called.
>
> An XSLT transformation can involve processing of more than one XML
> documents and even of documents that don't exist at the start of the
> transformation. In some cases there isn't any source document at all.
> In many cases the source XML document isn't "read" as it is already
> available as a parsed XML document in RAM.
>
> Some related interesting questions: "is an index garbage collected, is
> an index created many time for the same document, can an index be
> created only once and retained indefinitely -- even between
> transformations:?"
>
> I don't think any answers to these questions have been specified in
> any of the W3C XSLT specifications.
>
> This means that the programmer has almost no control of the index
> creation and destruction.
>
> In XSLT 3.0 one would be able to use a new data type -- map, which can
> be used to provide the same functionality as keys -- and is in under
> the control of the XSLT programmer.
>
> Cheers,
> Dimitre.
>
>
> On Mon, Aug 6, 2012 at 10:16 AM, FAIR, ED <ef7193@xxxxxxx> wrote:
>> Hi,
>>
>> I am not totally new to xslt but have a very basic question about keys.
>>
>> My stylesheets are working but performance is starting to suffer as document sizes have grown.  I'm trying to improve performance by adding and using keys.
>>
>> I understand that an xsl:key creates something like an associative array that can be used to cross-reference elements in my document using the key() function.   I have no problem understanding these concepts.
>>
>> My question is:  when is the associative array built?  Is it built entirely in the beginning, as the source document is first read into memory?  Or is it built incrementally, as each template is matched during transformation?
>>
>> FWIW, I am using xslt 1.0, xsltproc in Solaris 10:
>>
>>       $ xsltproc -V
>>       Using libxml 20623, libxslt 10115 and libexslt 812
>>       xsltproc was compiled against libxml 20623, libxslt 10115 and libexslt 812
>>       libxslt 10115 was compiled against libxml 20623
>>       libexslt 812 was compiled against libxml 20623
>>       [vsadm@alnvitalpol2: /usr/home/vsadm/csv-pcrf-1 ]
>>       $
>>
>> ed
>>
>
>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> To avoid situations in which you might make mistakes may be the
> biggest mistake of all
> ------------------------------------
> Quality means doing it right when no one is looking.
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
> -------------------------------------
> Facts do not cease to exist because they are ignored.
> -------------------------------------
> I finally figured out the only reason to be alive is to enjoy it.



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.


Current Thread
Keywords