I have a parts manual that is composed of a set of several XML files that are segmented by different part groups. Each part grouping contains several tables of information related to individual parts, including a unique part number. Each individual part is contained as a single row in the table. I've added an empty column to these tables that will point out if sale of a part is restricted by either a "yes" or "no" value once I run it through my transform.
I wrote an XSLT transformation to find a part number in a lookup file, compare it to a part number in the document I'm processing, and when they match, populate the empty column with either "yes" or "no" based on what is listed in the lookup XML document.
The part numbers are unique. However, some parts are used with multiple part groups. While the parts manual is composed of several XML files, the lookup file I'm using is based off of a BOM. So, it's one big XML document that contains all the parts for every group.
The XML document I'm processing looks like this:
<reference>
<title>Part Group A</title>
<refbody>
<section>
<image href="partGroupA.svg"/>
</section>
<simpletable>
<sthead>
<stentry>Annotation</stentry>
<stentry>Part Name</stentry>
<stentry>Restricted?</stentry>
<stentry>Part Description</stentry>
<stentry>Part Number</stentry>
<stentry>Quantity</stentry>
<stentry>Comment</stentry>
</sthead>
<strow>
<stentry translate="no" props="annotation">1</stentry>
<stentry translate="no" props="part-name">SomePart</stentry>
<stentry translate="no" props="part-restrict"></stentry>
<stentry translate="yes" props="part-desc">SomePart</stentry>
<stentry translate="no" props="part-number">1234567-00-A</stentry>
<stentry translate="no" props="quantity">1</stentry>
<stentry translate="yes" props="comment">Some comment</stentry>
</strow>
<strow>
<stentry translate="no" props="annotation">2</stentry>
<stentry translate="no" props="part-name">AnotherPart</stentry>
<stentry translate="no" props="part-restrict"></stentry>
<stentry translate="yes" props="part-desc">AnotherPart</stentry>
<stentry translate="no" props="part-number">2345678-00-A</stentry>
<stentry translate="no" props="quantity">1</stentry>
<stentry translate="yes" props="comment">Another comment</stentry>
</strow>
...
</simpletable>
</refbody>
</reference>
The look up XML document contains this:
...
<strow>
<stentry props="part-section">Part Group A</stentry>
<stentry props="part-name">SomePart</stentry>
<stentry props="part-number">1234567-00-A</stentry>
<stentry props="part-restrict">Yes</stentry>
</strow>
<strow>
<stentry props="part-section">Part Group A</stentry>
<stentry props="part-name">AnotherPart</stentry>
<stentry props="part-number">2345678-00-A</stentry>
<stentry props="part-restrict">No</stentry>
</strow>
...
<strow>
<stentry props="part-section">Part Group B</stentry>
<stentry props="part-name">SomePart</stentry>
<stentry props="part-number">1234567-00-A</stentry>
<stentry props="part-restrict">No</stentry>
</strow>
...
My XSLT transformation looks like this:
<xsl:output method="xml" encoding="UTF-8" indent="yes" doctype-system="reference.dtd" doctype-public="-//OASIS//DTD DITA Reference//EN"/>
<xsl:strip-space elements="*"/>
<xsl:key name="part-number" match="strow" use="stentry[@props='part-number']" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="stentry[@props='part-restrict']">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:variable name="matching-part" select="key('part-number', ../stentry[@props='part-number'], document('pm_restrict_redo-2.xml'))" />
<xsl:choose>
<xsl:when test="$matching-part">
<xsl:value-of select="$matching-part/stentry[@props='part-restrict']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
This works to a point. Since in some cases, the part number is used multiple times in different part groups (for different systems, subsystems, etc.) and is listed multiple times in the BOM lookup, my transform ends up listing "yes" or "no" for each occurrence of the part. The resulting XML looks like this:
<strow>
<stentry translate="no" props="annotation">1</stentry>
<stentry translate="no" props="part-name">SomePart</stentry>
<stentry translate="no" props="part-restrict">yes no</stentry>
<stentry translate="yes" props="part-desc">SomePart</stentry>
<stentry translate="no" props="part-number">1234567-00-A</stentry>
<stentry translate="no" props="quantity">1</stentry>
<stentry translate="yes" props="comment">Some comment</stentry>
</strow>
What I'm trying to do is transform XML related to a specific part group and limit the listing of a "yes" or "no" value to what is captured for that part group. Instead, what I'm getting is all the "yes" and "no" values for every occurrence of the part in the BOM.
Any help appreciated.