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

Steve

Hi Steve

the following stylesheet shuold easily be adapted to your needs.

Best regards
Uli


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version=“1.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>

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

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

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

</xsl:template>

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

</xsl:stylesheet>