[xsl] current node attribute as predicate

Subject: [xsl] current node attribute as predicate
From: Antonie Botes <antonie.botes@xxxxxxxxxxx>
Date: Fri, 25 Oct 2002 11:17:26 +0100
I use only a subset of the XML file to be processed as templates. The rest
of the XML is source data from which to read certain values relating it to
the current node via an attribute of the current node. The only way I know
of that works is using a variable to which I assign the attribute, then by
using the variable in the predicate. Apologies if this is a really basic
question. Here is an example:


<?xml version="1.0" encoding="utf-8" ?>
	<item itemcode="Item1">
		<description>description 1</description>
	<item itemcode="Item2">
		<description>description 2</description>
		<purchase item="Item2" number="2" />
		<purchase item="Item1" number="1" />

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
	<xsl:template match="invoice">
		<xsl:apply-templates />
	<xsl:template match="purchase">
		<xsl:variable name="ItemText">
			<xsl:value-of select="@item" />
		<xsl:copy-of select="/inventory/item[@itemcode=$ItemText]"
	<xsl:template match="item" />

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread