First of all, you need to read your second XML document. You can do that with document() function:
<xsl:variable name="secondDocument" select="document('example2.xml')"/>
Now you can query the second document by addressing the "secondDocument" variable. To match Types and IDs you can have a simple template:
<xsl:template match="Node">
<xsl:variable name="type" select="@Type"/>
<xsl:variable name="id" select="@ID"/>
<xsl:value-of select="$secondDocument//Node[@Type=$type and @ID=$id]"/>
</xsl:template>
However, this algorithm makes XSLT processor to search the second document every time the first document has a reference to it. This process is slow. If your documents are small, you will not notice any significant delay so this approach will be sufficient. But if you have huge documents, the delay may be unacceptable. Then you have no better choice than using key() function. When you define your keys, XSLT processor builds an index in memory to perform a lookup, and such a lookup is very fast.
Hard part is to make key() function work on another document. Fortunately, Bob DuCharme
nicely provided us with an example of how this can be done
I changed his xq487.xsl to match your example and also changed your example (a little) to match his XSLT
I added root elements and changed Node element to aNode in the second XML to avoid confusion.
XSL: (shamelessly plagiarized)
<!-- xq487.xsl: converts xq484.xml into xq493.xml -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:variable name="secondDoc" select="document('xq485.xml')"/>
<xsl:key name="lookupID" match="aNode" use="@ID"/>
<xsl:template match="root">
<xsl:apply-templates select="$secondDoc"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="root1"/>
<xsl:template match="Node">
<xsl:variable name="currentNodeID" select="@ID"/>
<xsl:for-each select="$secondDoc">
<xsl:value-of select="key('lookupID',$currentNodeID)"/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
XML:
<root>
<Node Type="FirstType" ID="1"/>
<Node Type="SecondType" ID="1"/>
<Node Type="FirstType" ID="2"/>
<Node Type="FirstType" ID="3"/>
<Node Type="SecondType" ID="2"/>
</root>
and the second XML:
<root1>
<aNode Type="FirstType" ID="1">Content for FirstType of Node ID 1</aNode>
<aNode Type="SecondType" ID="1">Content for SecondType of Node ID 1</aNode>
<aNode Type="FirstType" ID="2">Content for FirstType of Node ID 2</aNode>
<aNode Type="FirstType" ID="3">Content for FirstType of Node ID 3</aNode>
<aNode Type="SecondType" ID="2">Content for SecondType of Node ID 4</aNode>
</root1>
[This message has been edited by Mapraputa Is (edited August 14, 2001).]