Looping questions
Greetings,
Any advice is greatly appreciated.
I am thinking there must be a better way to loop through multiple line item tags and determine if a item is a extra service and place it accordingly
I am using Saxxon and attempting to create output based on received line items in an XML document.
I determine based on a DUNS number and item ID called in an out side method weather the item in questions is an extra service. If this is "False", not an extra service then I create a line item. If the item is a extra service ="True" I must determine if it belongs to a line item in the XML by an ID and create the data as a child inside the line item.
Finally if it is a extra service and does not belong to a line item I will create the extra service last as a summery level applying to the entire Purchase order.
The code I have for the first round works but is heavy in looping over the data, 20 line items would have to loop 200 times to determine if there is any relationship between the lines and extra service items. There is not a restriction on when a line item could be a extra service to the line or summery level.
Is there a better way to trim down the loops with recursory or X-path parent-child relationships?
Please find attached a trimmed down source XML and the style sheet.
XML:
<ShipNotice>
<Detail>
<LineItemInfo>
<NLineItemNumber>2836049</NLineItemNumber>
<LimitBalance/>
</LineItemInfo>
<SProduct>
<SupplierDunsNum>007811874</SupplierDunsNum>
<SupplierCUPC>1050181</SupplierCUPC>
<SupplierProductCode>1050181</SupplierProductCode>
<SupplierProprietaryCode>1050181</SupplierProprietaryCode>
<Description>BROCCOLI</Description>
<SupplierPartnerLineItemNumber>2836049</SupplierPartnerLineItemNumber>
<SupplierQty>200</SupplierQty>
<SupplierPrice>9.3500</SupplierPrice>
</SProduct>
</Detail>
<Detail>
<LineItemInfo>
<NLineItemNumber>2836050</NLineItemNumber>
<LimitBalance/>
</LineItemInfo>
<SProduct>
<SupplierDunsNum>007811874</SupplierDunsNum>
<SupplierCUPC>10501819</SupplierCUPC>
<SupplierProductCode>10501819</SupplierProductCode>
<SupplierProprietaryCode>10501819</SupplierProprietaryCode>
<Description>Cabbage</Description>
<SupplierPartnerLineItemNumber>2836050</SupplierPartnerLineItemNumber>
<SupplierQty>100</SupplierQty>
<SupplierPrice>11.3500</SupplierPrice>
</SProduct>
</Detail>
<Detail>
<LineItemInfo>
<NLineItemNumber>2836049</NLineItemNumber>
<LimitBalance/>
</LineItemInfo>
<SProduct>
<SupplierDunsNum>007811874</SupplierDunsNum>
<SupplierCUPC>900050</SupplierCUPC>
<SupplierProductCode>90005</SupplierProductCode>
<SupplierProprietaryCode>90005</SupplierProprietaryCode>
<Description>Temp Recorder</Description>
<SupplierPartnerLineItemNumber>2836049</SupplierPartnerLineItemNumber>
<SupplierQty>1</SupplierQty>
<SupplierPrice>25.3500</SupplierPrice>
</SProduct>
</Detail>
<Detail>
<LineItemInfo>
<NLineItemNumber>0</NLineItemNumber>
<LimitBalance/>
</LineItemInfo>
<SProduct>
<SupplierDunsNum>007811874</SupplierDunsNum>
<SupplierCUPC>90005</SupplierCUPC>
<SupplierProductCode>90005</SupplierProductCode>
<SupplierProprietaryCode>90005</SupplierProprietaryCode>
<Description>Temp Recorder</Description>
<SupplierPartnerLineItemNumber>0</SupplierPartnerLineItemNumber>
<SupplierQty>1</SupplierQty>
<SupplierPrice>25.3500</SupplierPrice>
</SProduct>
</Detail>
</ShipNotice>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:checkEX="com.common.Interface">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="ShipNotice">
<xsl:element name="PO">
<xsl:for-each select="Detail">
<xsl:variable name="ZP"><xsl:value-of select="SProduct/SupplierProductCode"/></xsl:variable>
<xsl:variable name="nullLineNum" select="LineItemInfo/NLineItemNumber"/>
<xsl:variable name="sDUNSline"><xsl:value-of select="SProduct/SupplierDunsNum"/></xsl:variable>
<xsl:variable name="isLineIsEX"><xsl:value-of select="checkEX:isExtraService($ZP, $sDUNSline)"/></xsl:variable>
<xsl:choose>
<xsl:when test="$isLineIsEX = 'false'">
<xsl:element name="POEntry">
<xsl:element name="Price">
<xsl:value-of select="SProduct/SupplierPrice"/>
</xsl:element>
<xsl:element name="Quantity">
<xsl:value-of select="SProduct/SupplierActualQtyShipped"/>
</xsl:element>
<xsl:for-each select="../Detail">
<xsl:variable name="sDUNS"><xsl:value-of select="SProduct/SupplierDunsNum"/></xsl:variable>
<xsl:variable name="isLineEX"><xsl:value-of select="checkEX:isExtraService(SProduct/SupplierProductCode, $sDUNSline)"/></xsl:variable>
<xsl:choose>
<xsl:when test="$isLineEX ='true' and (LineItemInfo/NLineItemNumber = $nullLineNum and $nullLineNum !='0')">
<xsl:element name="LineItemExtraServices">
<xsl:element name="price"><xsl:value-of select="SProduct/SupplierPrice"/></xsl:element>
<xsl:element name="quantity"><xsl:value-of select="SProduct/SupplierLineQty"/></xsl:element>
<xsl:element name="LiEsAudit">
<xsl:element name="SellerEsp">
<xsl:element name="code"><xsl:value-of select="SProduct/SupplierCUPC"/></xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:element name="productCode">
<xsl:value-of select="SProduct/SupplierProductCode"/>
</xsl:element>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="Detail">
<xsl:variable name="ZP"><xsl:value-of select="SProduct/SupplierProductCode"/></xsl:variable>
<xsl:variable name="nullLineNum" select="LineItemInfo/NLineItemNumber"/>
<xsl:variable name="sDUNSline"><xsl:value-of select="SProduct/SupplierDunsNum"/></xsl:variable>
<xsl:variable name="isLineIsEX"><xsl:value-of select="checkEX:isExtraService($ZP, $sDUNSline)"/></xsl:variable>
<xsl:variable name="sDUNS"><xsl:value-of select="SProduct/SupplierDunsNum"/></xsl:variable>
<xsl:variable name="isLineEX"><xsl:value-of select="checkEX:isExtraService(SProduct/SupplierProductCode, $sDUNSline)"/></xsl:variable>
<xsl:choose>
<xsl:when test="$isLineEX='true' and (LineItemInfo/NLineItemNumber and $nullLineNum ='0')">
<xsl:element name="POExtraServices">
<xsl:element name="price"><xsl:value-of select="SProduct/SupplierPrice"/></xsl:element>
<xsl:element name="quantity"><xsl:value-of select="SProduct/SupplierActualQtyShipped"/></xsl:element>
<xsl:element name="PoEsAudit">
<xsl:element name="SellerEsp">
<xsl:element name="code"><xsl:value-of select="SProduct/SupplierProductCode"/></xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thank you
|