For cross-references, I would use a key e.g.
<xsl:param name="frig" expand-text="no">
<refrigerator>
<item name="appLe"/>
<item name="Grape"/>
</refrigerator>
</xsl:param>
<xsl:key name="frig-item-by-name" match="refrigerator/item" use="lower-case(@name)"/>
Then you can select e.g.
<xsl:template match="recipe">
<section>
<h1>{local-name()}</h1>
<section>
<h2>Available ingredients</h2>
<xsl:where-populated>
<ul>
<xsl:apply-templates select="ingredient[key('frig-item-by-name', lower-case(@name), $frig)]"/>
</ul>
</xsl:where-populated>
</section>
<section>
<h2>Ingredients to buy</h2>
<xsl:where-populated>
<ul>
<xsl:apply-templates select="ingredient[not(key('frig-item-by-name', lower-case(@name), $frig))]"/>
</ul>
</xsl:where-populated>
</section>
</section>
</xsl:template>
Of course, if the data of the frig is in the same document as the primary input, drop the parameter and drop the third argument of the key
function calls. And of course instead of inlining the data, as I did for self-containedness of the example, if the data is in a second document, use e.g. <xsl:param name="frig" select="doc('frig-data.xml')"/>
.
Complete sample to put above snippets into context:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes"
version="3.0">
<xsl:param name="frig" expand-text="no">
<refrigerator>
<item name="appLe"/>
<item name="Grape"/>
</refrigerator>
</xsl:param>
<xsl:key name="frig-item-by-name" match="refrigerator/item" use="lower-case(@name)"/>
<xsl:template match="recipe">
<section>
<h1>{local-name()}</h1>
<section>
<h2>Available ingredients</h2>
<xsl:where-populated>
<ul>
<xsl:apply-templates select="ingredient[key('frig-item-by-name', lower-case(@name), $frig)]"/>
</ul>
</xsl:where-populated>
</section>
<section>
<h2>Ingredients to buy</h2>
<xsl:where-populated>
<ul>
<xsl:apply-templates select="ingredient[not(key('frig-item-by-name', lower-case(@name), $frig))]"/>
</ul>
</xsl:where-populated>
</section>
</section>
</xsl:template>
<xsl:template match="ingredient">
<li>{lower-case(@name)}</li>
</xsl:template>
<xsl:output method="html" indent="yes" html-version="5"/>
<xsl:template match="/">
<html>
<head>
<title>.NET XSLT Fiddle Example</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>