XSLT using lookup table
Posted: Tue Mar 30, 2021 11:12 pm
Hello,
I am a beginner writing XSLTs and I am stumped with writing one that refs to a lookup table and returns a result. I have the following:
<mrp><mrp-setup-item>
<name>Rivet</name>
<qty>2</qty>
<itemref>
<xref wpid="S20002#ROW015" itemid="ROW015"/>
</itemref>
</mrp-setup-item>
<mrp-setup-item>
<name>Washer</name>
<qty>4</qty>
<itemref>
<xref wpid="S20002#ROW083" itemid="ROW083"/>
</itemref>
</mrp-setup-item>
I need to grab the xref itemid attribute, find it in my lookup.xml and return the child of itemid in the lookup.xml into the attribute.
My lookup.xml looks like this:
<item><rowitem><id>ROW015</id><itemid>MRP_NSN_5320-01-080-9250</itemid></rowitem></item>
<item><rowitem><id>ROW016</id><itemid>MRP_NSN_5315-01-210-7570</itemid></rowitem></item>
<item><rowitem><id>ROW017</id><itemid>MRP_NSN_5315-00-240-0997</itemid></rowitem></item>
<item><rowitem><id>ROW018</id><itemid>MRP_NSN_5315-00-902-8352</itemid></rowitem></item>
<item><rowitem><id>ROW019</id><itemid>MRP_NSN_5315-00-298-9845</itemid></rowitem></item>
<item><rowitem><id>ROW019-10</id><itemid>MRP_NSN_5315-00-882-1438</itemid></rowitem></item>
<item><rowitem><id>ROW020</id><itemid>MRP_NSN_5315-00-823-8746</itemid></rowitem></item>
<item><rowitem><id>ROW021</id><itemid>MRP_NSN_5315-00-058-9756</itemid></rowitem></item>
Currently, my XSLT has this written and it returns an empty itemid attribute.
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="MRPITEMS">file:///C:/BAE/FAASV/Maintwp/mrp_Lookup.xml</xsl:variable>
<xsl:variable name="MRPnum" select="@itemid"></xsl:variable>
<xsl:template match="mrp-setup-item">
<xsl:choose>
<xsl:when test="contains(xref/@itemid,ROW)"></xsl:when>
<mrp-setup-item>
<xsl:copy-of select="name"></xsl:copy-of>
<xsl:copy-of select="qty"></xsl:copy-of>
<itemxref><xref>
<xsl:attribute name="wpid">S20006-9-2350-372</xsl:attribute>
<xsl:attribute name="itemid"><xsl:value-of select="document($MRPITEMS)//child::id=$MRPnum/child::itemid"/>"</xsl:attribute>
</xref></itemxref>
</mrp-setup-item>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
I look forward to any help I receive.
Cathy
I am a beginner writing XSLTs and I am stumped with writing one that refs to a lookup table and returns a result. I have the following:
<mrp><mrp-setup-item>
<name>Rivet</name>
<qty>2</qty>
<itemref>
<xref wpid="S20002#ROW015" itemid="ROW015"/>
</itemref>
</mrp-setup-item>
<mrp-setup-item>
<name>Washer</name>
<qty>4</qty>
<itemref>
<xref wpid="S20002#ROW083" itemid="ROW083"/>
</itemref>
</mrp-setup-item>
I need to grab the xref itemid attribute, find it in my lookup.xml and return the child of itemid in the lookup.xml into the attribute.
My lookup.xml looks like this:
<item><rowitem><id>ROW015</id><itemid>MRP_NSN_5320-01-080-9250</itemid></rowitem></item>
<item><rowitem><id>ROW016</id><itemid>MRP_NSN_5315-01-210-7570</itemid></rowitem></item>
<item><rowitem><id>ROW017</id><itemid>MRP_NSN_5315-00-240-0997</itemid></rowitem></item>
<item><rowitem><id>ROW018</id><itemid>MRP_NSN_5315-00-902-8352</itemid></rowitem></item>
<item><rowitem><id>ROW019</id><itemid>MRP_NSN_5315-00-298-9845</itemid></rowitem></item>
<item><rowitem><id>ROW019-10</id><itemid>MRP_NSN_5315-00-882-1438</itemid></rowitem></item>
<item><rowitem><id>ROW020</id><itemid>MRP_NSN_5315-00-823-8746</itemid></rowitem></item>
<item><rowitem><id>ROW021</id><itemid>MRP_NSN_5315-00-058-9756</itemid></rowitem></item>
Currently, my XSLT has this written and it returns an empty itemid attribute.
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="MRPITEMS">file:///C:/BAE/FAASV/Maintwp/mrp_Lookup.xml</xsl:variable>
<xsl:variable name="MRPnum" select="@itemid"></xsl:variable>
<xsl:template match="mrp-setup-item">
<xsl:choose>
<xsl:when test="contains(xref/@itemid,ROW)"></xsl:when>
<mrp-setup-item>
<xsl:copy-of select="name"></xsl:copy-of>
<xsl:copy-of select="qty"></xsl:copy-of>
<itemxref><xref>
<xsl:attribute name="wpid">S20006-9-2350-372</xsl:attribute>
<xsl:attribute name="itemid"><xsl:value-of select="document($MRPITEMS)//child::id=$MRPnum/child::itemid"/>"</xsl:attribute>
</xref></itemxref>
</mrp-setup-item>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
I look forward to any help I receive.
Cathy