Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2003, 05:14 PM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Interview Questions, C# Interview Questions, dotnetuncle .NET Framework 2.0 4 June 22nd, 2019 07:03 AM
Looping ssaranam SQL Server 2005 2 April 17th, 2008 01:40 AM
looping mrjoka Classic ASP Basics 1 September 26th, 2007 12:21 AM
Looping deepsea007 XSLT 1 June 14th, 2007 12:13 PM
Looping..? dedex C# 2 January 6th, 2005 11:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.