xsl-list
[Top] [All Lists]

current node attribute as predicate

2002-10-25 03:17:26
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
________________________________________

<?xml version="1.0" encoding="utf-8" ?>
<inventory>
        <item itemcode="Item1">
                <price>10.50</price>
                <description>description 1</description>
        </item>
        <item itemcode="Item2">
                <price>20.00</price>
                <description>description 2</description>
        </item>
        <invoice>
                <date>19/12/2002</date>
                <purchase item="Item2" number="2" />
                <purchase item="Item1" number="1" />
        </invoice>
</inventory>


XSLT
_____________________________________________________
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:template match="invoice">
                <xsl:apply-templates />
        </xsl:template>
        <xsl:template match="purchase">
                <xsl:variable name="ItemText">
                        <xsl:value-of select="@item" />
                </xsl:variable>
                <xsl:copy-of select="/inventory/item[(_at_)itemcode=$ItemText]"
/>
        </xsl:template>
        <xsl:template match="item" />
</xsl:stylesheet>

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



<Prev in Thread] Current Thread [Next in Thread>