Stephen Cranefield ([EMAIL PROTECTED]) writes:
>Does Xalan-Java apply keys to additional source documents loaded using
>the document() function?
and later, he wrote:
>I missed all of this [12.2 context-node stuff], but now that I have
>added the for-each to my code it works.
Could you please show us how you added that for-each? I tried to make a
verson of Uche's example and couldn't get it to work without a for-each
encompassing the call to key(), which I think is required by the spec.
Recapitulating the issue:
>I was trying to follow Uche Ogbuji's example code and
>thought that just writing this as a top-level element would work to
>set up the keys:
> <xsl:variable name="load_java_reserved_words"
> select="document('java_reserved_words.xml')"/>
Apparently, Uche suggested this as a way to apply document() to a
file that has a data table that should populate a keyspace. In the
original example on DeveloperWorks, it was document('') to cause
reading of the stylesheet itself. But when key() is invoked, "it
returns a node-set containing nodes in the same document as the context
node..." to quote the spec. So you can't just create a keyspace in
memory and use key() blindly; the keyspace is associated with a source
document that must be the source of the context node, even if you have
to use for-each to change your point of view.
This issue relates to the recent suggestion that Xalan should have a
way to load pre-generated keyspaces into memory. While keys are good,
I think that the 1.0 spec is weak on the issue of preparing a keyspace
and making it re-usable.
Our test case IDKEY18, which is taken from the example in XSLT 12.2,
works as specified. So we can indeed "apply keys to additional source
documents" per the question. Here's the crucial template:
<xsl:template match="bibref">
<xsl:variable name="lookup" select="."/>
<xsl:for-each select="document('bib.xml')">
<xsl:apply-templates select="key('bib',$lookup)"/>
</xsl:for-each>
</xsl:template>
NOTICE that we make no prior mention of the 'bib.xml' file and we do
not use xsl:variable or another method to force advance reading of the
file. I am now trying to expand this example to a case where the 'bib'
keyspace encompasses nodes from more than one file, and I expect that
the call to key() will only retrieve nodes from one file at a time. If
anyone disagrees with that expectation, please reply to the list. After
that, I'd go on to make another test where document(filelist) refers
to more than one file by indirection--any bets on what will happen?
.................David Marston