keys - across different files

Sax errors apart <sorry Mike/>
Below is an example of using keys across / between
two different files, which the rec says they are not
supposed to be, and Mike Kays books says they can be.
Objective was to find out if all the 8 years of files
reflected in a database were actually still in the
flat file store.
key1.xml is the database output,
key2.xml is the flat file system record (thanks Chris)
I found it quite a struggle, 3 mins for DC is the challenge :-)
Hope it helps someone else
Regards DaveP
Key1.xml (key2 inserted as comment)
<?xml version="1.0" standalone="yes"?>
<wrapper>
<state>xxxx</state> <!-- matches in key 2 -->
<state>yyyy</state><!-- matches in key2 -->
<state>aaaa</state><!-- match fails -->
<state>zzzz</state><!-- matches in key2 -->
<state>zzzB</state><!-- matches again in key2 -->
<state>zzzA</state><!-- match fails -->
</wrapper>
<!-- This is key2.xml
<wrapper>
<st>xxxx</st>
<st>xxxY</st>
<st>xxxZ</st>
<st>yyyy</st>
<st>xxxB</st>
<st>zzzz</st>
<st>zzzz</st>
<st>zzzz</st>
<st>zzzz</st>
</wrapper>
-->
Stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform&quot;
version="1.0"
xmlns:saxon="http://icl.com/saxon&quot;
extension-element-prefixes="saxon">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<!--
Objective: to find all //st elements in key2.xml that have the same
content as the particular set of elements in key1.xml
In my case it was, do all the 'actuals' in the flat file system
have records in the database which is supposed to reflect the
flat file system. (I.e. the database is reflected in key1.xml, the
flat file system in key2.xml)
-->
<!-- key is in document 2, which must be the 'source' document -->
<xsl:key name="target-node-set" match="/wrapper/st" use="."/>
<!-- Root template on 'any document' -->
<xsl:template match="/">
<!-- Grab and hold the first file element in primary file context -->
<xsl:for-each select="document('key1.xml')">
<xsl:for-each select="/wrapper/state">
<!-- Save the context element -->
<xsl:variable name="here" select="."/>
<!-- Change context to document 2 -->
<xsl:for-each select="document('key2.xml')">
<xsl:if test="key('target-node-set', $here)">
Match on item <xsl:value-of select="$here"/> from key1
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
=============================
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list