Using XSLT to create a Bill of Materials

I am really struggling to see how to do this with XSLT.
Do I need to resort to Java or is there a neat XPATH & XSLT
mechanism for this?

I have a document with a list of parts followed by a list of assemblies that the parts potential may be in. The assemblies hold a ref to the parts. For example, 3 wires, 2 in an assembly, 1 not:

I need to create a bill of materials that lists the occurences of the
parts either within assemblies or on their own. For example:

I can count the total number of wires with a particular part number, eg count(//property[@name='PartNumber’and @val=‘PartABC’]). However, I need to do this in the context of an assembly and following the ref to a wire id.

Suggestions will be heartily welcome


Hi Steve

the following stylesheet shuold easily be adapted to your needs.

Best regards

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version=“1.0”

<xsl:output method=“xml” indent=“yes”/>

<xsl:template match=“parts”>
<xsl:apply-templates select="" mode=“material”/>

<xsl:template match=“assembly” mode=“material”>


<xsl:template match="
" mode=“material”>
<xsl:value-of select=“name()”/>, id=<xsl:value-of select="@id"/>
<xsl:when test="@id = …/assembly/assemblyelement/@ref">
in assembly
NOT in assembly