[xsl] How to create xsl:key that has a composite value in its "use" attribute?

Subject: [xsl] How to create xsl:key that has a composite value in its "use" attribute?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 15 Mar 2025 13:19:36 -0000
Hi Folks,

I have an XML document that contains <row> elements within a <BDRY> element:

<BDRY>
    <row>
        <BDRY_IDENT>ABC</BDRY_IDENT>
        <NAV_IDENT>VOR1</NAV_IDENT>
        <NAV_CTRY>US</NAV_CTRY>
        <NAV_TYPE>1</NAV_TYPE>
    </row>
    ...  <!-- thousands of row elements -->
</BDRY>

Also, within the XML document are <row> elements within an <ANAV> element:

<ANAV>
    <row>
        <ARPT_IDENT>Logan</ARPT_IDENT>
        <NAV_IDENT>VOR1</NAV_IDENT>
        <NAV_CTRY>US</NAV_CTRY>
        <NAV_TYPE>1</NAV_TYPE>
    </row>
    ...
</ANAV>

When I process one of the ANAV row elements, I want to select the row elements
in BDRY that match on NAV_IDENT, NAV_CTRY, NAV_TYPE. I believe the proper
terminology, is that I have a composite key, yes?

I would like to create an xsl:key for the BDRY rows and I want xsl:key to
specify that the rows to be selected are based on the composite key NAV_IDENT,
NAV_CTRY, NAV_TYPE. Here's how I specified xsl:key in my XSLT program:

<xsl:key	name="ANAV-to-BDRY" match="BDRY/row"
	use="NAV_IDENT, NAV_CTRY, NAV_TYPE "
	composite="yes"/>

Is that the correct way to specify xsl:key?

At the point in my program where I want to use the key, I have an ANAV row
element. I want to use its NAV_IDENT, NAV_CTRY, and NAV_TYPE child elements to
obtain BDRY row elements with matching fields, and output the <BDRY_IDENT>
element in each matching row:

<result>
    <xsl:sequence select="key('ANAV-to-BDRY', (NAV_IDENT, NAV_CTRY,
NAV_TYPE))/BDRY_IDENT"/>
</result>

That must be incorrect because the <result> element is erroneously populated
with a <BDRY_IDENT> element for every <row> element in <BDRY>:

<result>
    <BDRY_IDENT>...</BDRY_IDENT>
    <BDRY_IDENT>...</BDRY_IDENT>
    <BDRY_IDENT>...</BDRY_IDENT>
    ...  <!-- thousands of them -->
</result>

What am I doing wrong?

/Roger

Current Thread