[xsl] Can I create a key on elements in a non-primary XML document?

Subject: [xsl] Can I create a key on elements in a non-primary XML document?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 16 Mar 2025 14:20:13 -0000
Hi Folks,

When I run my XSLT program, I provide it with an input XML document. I call
that input XML document the "primary XML document." I successfully created
keys on elements in the primary XML document.

My XSLT program must also retrieve data from another, non-primary, XML
document. I create a variable to access the non-primary XML document:

<xsl:variable name="cc" select="doc('cc2areaCode.xml')/*" />

I successfully retrieved data from that non-primary XML document using this
code:

<xsl:sequence select="$cc/Row[Country eq $first-2-chars]/areaCode"/>

To speed up my XSLT program, I would like to create a key for the non-primary
XML document:

<xsl:key name="ARPT-to-CC" match="$cc/*/Row" use="Country"/>

And then use the key:

<xsl:copy-of select="key('ARPT-to-CC', $first-2-chars)/areaCode"/>

However, I have found that the xsl:copy-of outputs nothing.

Is it possible to create and use a key for a non-primary XML document?

/Roger

Current Thread