Re: [xsl] Problem with keys in for-each (?)

Subject: Re: [xsl] Problem with keys in for-each (?)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 14 Mar 2001 14:04:26 GMT
] <xsl:key name="itemKey" match="//*[local-name() = 'item']" 
] 			use="ancestor-or-self::*[@type][1]/@type" />

] created a hash table (or something) in memory that was then referenced by
] name via the key() function - the idea that the context would somehow affect
] this is bizarre. 

incidentally there is never any point in using // at the start of a
match expression. That generates a hash table (most likely)  or more
to the point it acts as if it creates a separate hash for each document.
key(x,y) looks up they keys for the document containing the context
node.


> <xsl:variable name="taxonomy" select="document('AlteredTaxonomy.xml')" />
> 
> When Mike says that the for-each on this variable changes the context to a
> *different document*, it means that the document I'm processing does not
> "include" any variables I have created during the processing of the
> stylesheet, those are "different documents" - or is it just variables that
> are created using document()?  

No variables are not local to documents. But each node in a node set
is contained in some document, and when you apply key() you are just
returned nodes from that document.
In the case above $taxonomy is a node set with a single node, the root
node of the document AlteredTaxonomy.xml so when you do
<xsl:for-each select="$taxonomy">
the context node is in the document  AlteredTaxonomy.xml and so you only
get keys from there.


In your stylesheet you have

    <xsl:apply-templates select="key('itemKey',
'ci:entityInformation.businessDescription')" />   

  </xsl:for-each> 


this apply-templates doesn't depend on the context node, so would
generate the same thing for each iteration of the for-each, is that
really what you want?

If you do, you could wrap it in

<xsl:for-each select="$root">

</xsl:for-each>

where root is defined by a top level
<xsl:variable name="root" select="/"/>
ie the root node of your original document.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread