key() doesn't work on ixsl:page() after ixsl:replace-content?
Not sure it's the best subject, but this is what seems to be happening here (see the last 2 templates): https://namedgraph.github.io/saxon-js2-test/client.xsl
Live demo: https://namedgraph.github.io/saxon-js2-test/
[@CLASS KEY] button.
I would expect the lookups to find
id('abc', ixsl:page()) (which it does) as well as
key('elements-by-class', 'some-class', ixsl:page()) (which it doesn't).
#2 Updated by Martin Honnen 3 months ago
I think the problem might simply be that the index for a key declaration is built-once but is not later updated when the document is changed. At https://martin-honnen.github.io/xslt/2021/saxon-js-key-test-ee1.html there is an initial value for the key call but it remains constant while a direct attribute based selection does take the actual state of the tree into account. Solely a guess, however.
#4 Updated by Martynas Jusevicius 3 months ago
You're right, I was still generating SEF with 2.1. Now it should be 2.2 for real.
The key thing is not great then. If ID lookups can work, I would keys expect to work as well. But lets see what Saxonica says :)
As a workaround, I'm trying to call the key on
$xhtml to get IDs of those elements and then use
#7 Updated by Martin Honnen 3 months ago
For accumulators on HTML documents there is a warning: "Accumulator values are attached to DOM nodes in situ. This means a DOM node can't have different values for the same accumulator name in different transformations. This is likely to be a permanent restriction. Advice for users: do not use accumulators on the HTML document, because it is mutable.".
Perhaps the same holds for keys?
#8 Updated by Debbie Lockett 3 months ago
Martin is right that the key index is only built once, but since the HTML page is mutable this is not necessarily good enough. As Mike and Martin have noted, this restriction is unfortunately not documented. So in the short-term, we need to update the documentation to include a warning about the use of keys for nodes in the HTML page.
In the long term, we should improve the implementation so that such keys are actually usable. The key indexes should be rebuilt if the HTML page has any (relevant) changes.
Please register to edit this issue