select="document('')/*/book:category[@code=current()/@category]/@desc"
File: Data.xml
<?xml version="1.0"?>
<booklist>
<book category="S">
<title>title 1</title>
<author>author 1</author>
</book>
<book category="FC">
<title>author 1</title>
<author>author 1</author>
</book>
<book category="FC">
<title>title 3</title>
<author>author 1</author>
</book>
<book category="CS">
<title>title 4</title>
<author>author 1</author>
<author>author 2</author>
<author>author 3</author>
<author>author 4</author>
</book>
</booklist>
File: Transform.xslt
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:book="books.uri" exclude-result-prefixes="book">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="//book">
<h1>
<xsl:value-of select="title" />
</h1>
<p>
Category:
<xsl:value-of select="document('')/*/book:category[@code=current()/@category]/@desc" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
<book:category code="S" desc="Science" />
<book:category code="CS" desc="Computing" />
<book:category code="FC" desc="Children's Fiction" />
</xsl:transform>
Output:
<html>
<body>
<h1>title 1</h1>
<p>
Category:
Science
</p>
<h1>author 1</h1>
<p>
Category:
Children's Fiction
</p>
<h1>title 3</h1>
<p>
Category:
Children's Fiction
</p>
<h1>title 4</h1>
<p>
Category:
Computing
</p>
</body>
</html>
Related examples in the same category