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 July 16th, 2008, 03:47 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Have a problem in For-each loop

Actually i have 2 DeliveryHeader child nodes in my xml document.I sue for-each loop to display both the DeliveryHeader/ShipTo/@SiteId.But when i use the for-each loop i get only the first record repeated twice.

The following is the code which i have written.
Code:
<xsl:variable name="deliveries"             select="./ContractDetail/PurchaseOrderSet
/PurchaseOrder/PODetail/ItemInfo/DeliverySet/Delivery
/DeliveryHeader/ShipTo"/>

<xsl:for-each select="$deliveries">
          <xsl:value-of select = "$deliveries/@SiteId"/>
Following is the xml for my xsl.
Code:
<?xml version="1.0" encoding="US-ASCII"?>
<?xml-stylesheet type="text/xsl" href="ClarksOrderView.xsl"?>
<Contract>
  <ContractDetail>
    <PurchaseOrderSet Count="1">
      <PurchaseOrder PurchaseOrderId="180762" PurchaseOrderReference="" PurchaseOrderNumber="129889" Revision="000">
        <POHeader POId="180762" POReference="" PONumber="129889" IceNumber="136912" Revision="000" CustomerRevisionNumber="" IceCreationDate="2007-04-13" PODate="2006-12-01" ContractId="180762" ContractNumber="129889" OrderType="" BuyerOrderType="SA" BuyerId="19228" BuyerName="THE CLARKS COMPANIES, N.A." ControlOfficeId="2608" ControlOfficeName="CLARKS REGIONAL OFFICE BRAZIL" AgentId="" AgentName="" OriginalAgentExternalCode="" VendorId="19562" VendorName="QA VENDOR A" OriginalVendorExternalCode="" TotalQuantity="400" TotalValue="2960" Currency="USD" RequestDate="2006-12-20" TermsOfPayment="60" TermsOfSale="FOB" TermsTypeCode="" TermsDescription="" TermsBasisDateCode="" TermsDiscountAmount="" TermsDiscountPercent="" TermsDiscountDueDate="" TermsDiscountDaysDue="" TermsNetDueDate="" TermsNetDaysDue="" Status="Entered" Downloaded="False" BuyerDepartmentCode="C" CountryOfOrigin="" EarliestShipmentDate="" ShipDate="2006-12-20" LatestShipmentDate="" CancelIfNotShippedByDate="" EarliestDeliveryDate="" RequestedDeliveryDate="" LatestDeliveryDate="" FreightTermsCode="" PackingInstructions="" ShippingInstructions="" Attribute1="58201" Attribute2="58201" Attribute4="SUNRISE">
          <VariableDataSet>
            <VariableDataElement Code="10" Name="Order Type" Value="CLK" />
            <VariableDataElement Code="20" Name="FOB Point" Value="58201" />
            <VariableDataElement Code="30" Name="Port of Lading" Value="58201" />
            <VariableDataElement Code="70" Name="Vendor" Value="SUNRISE" />
          </VariableDataSet>
          <NoteSet />
        </POHeader>
        <PODetail>
          <ItemInfo>
            <DeliverySet Count="2">
              <Delivery>
                <DeliveryHeader ShipToSiteId="5497" ShipToCode="" ShipMethod="OCEAN" DeliveryName="" DeliverySequence="" EarliestShipmentDate="" ShipDate="2006-12-20" LatestShipmentDate="" CancelIfNotShippedByDate="" EarliestDeliveryDate="" RequestedDeliveryDate="" LatestDeliveryDate="" DateRequestedCurrent="2006-12-20" DateRequestedCurrentStart="2006-12-20" DateRequestedCurrentEnd="2006-12-20">
                  <ShipTo SiteId="5497" SiteName="HANOVER" CustomerSiteCode="EXT-5497" SiteType="" CustomerSiteCodeDisplay="">
                    <Address AddressId="5497" Name="HANOVER" Line1="455 N. MADISON STREET" Line2="HANOVER, P.A. 17331" Line3="USA" Line4="" City="N/A" PostalCode="" County="" State="N/A" Province="" Country="N/A" />
                  </ShipTo>
                  <BillTo SiteId="2938" SiteName="Adr_Main" CustomerSiteCode="890AdrExt" SiteType="OTHER" CustomerSiteCodeDisplay="">
                    <Address AddressId="2938" Name="Adr_Main" Line1="789 Union Street" Line2="3rd st" Line3="" Line4="" City="Natick" PostalCode="02188" County="" State="MA" Province="" Country="USA" />
                  </BillTo>
                </DeliveryHeader>
                <DeliveryHeader ShipToSiteId="5498" ShipToCode="" ShipMethod="OCEANS" DeliveryName="" DeliverySequence="" EarliestShipmentDate="" ShipDate="2006-12-21" LatestShipmentDate="" CancelIfNotShippedByDate="" EarliestDeliveryDate="" RequestedDeliveryDate="" LatestDeliveryDate="" DateRequestedCurrent="2006-12-20" DateRequestedCurrentStart="2006-12-20" DateRequestedCurrentEnd="2006-12-20">
                  <ShipTo SiteId="5498" SiteName="HANOVER" CustomerSiteCode="EXT-5497" SiteType="" CustomerSiteCodeDisplay="">
                    <Address AddressId="5498" Name="HANOVER" Line1="455 N. MADISON STREET" Line2="HANOVER, P.A. 17331" Line3="USA" Line4="" City="N/A" PostalCode="" County="" State="N/A" Province="" Country="N/A" />
                  </ShipTo>
                  <BillTo SiteId="2939" SiteName="Adr_Main" CustomerSiteCode="890AdrExt" SiteType="OTHER" CustomerSiteCodeDisplay="">
                    <Address AddressId="2938" Name="Adr_Main" Line1="789 Union Street" Line2="3rd st" Line3="" Line4="" City="Natick" PostalCode="02188" County="" State="MA" Province="" Country="USA" />
                  </BillTo>
                </DeliveryHeader>
              </Delivery>
            </DeliverySet>
          </ItemInfo>
        </PODetail>
      </PurchaseOrder>
    </PurchaseOrderSet>
  </ContractDetail>
</Contract>
 
Old July 16th, 2008, 03:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Once you have set $deliveries as the context node any selections are relative to it so within your for-each (which is not a loop) you need
Code:
<xsl:value-of select = "$@SiteId"/>
Your code selects the value-of "$deliveries/@SiteId" which, in XSLT 1.0, will be the value of the first node selected by this expression.

(PS extraneous $ in the above expression, should be <xsl:value-of select = "@SiteId"/>

--

Joe (Microsoft MVP - XML)
 
Old July 16th, 2008, 05:20 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Joe made a typo - should be select="@SiteId".

$deliveries is the set of all deliveries. It doesn't magically change its meaning inside the for-each to mean the current delivery. Inside the for-each the current node is referred to as ".", so "./@SiteId", which abbreviates to "@SiteId".

(Perhaps you're thinking of SQL, where "select DELIV.Item from DELIV" behaves this way).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
loop problem smilesmita Pro PHP 1 November 2nd, 2007 02:15 AM
Loop problem! Please help me!! olud ASP.NET 1.0 and 1.1 Basics 2 March 19th, 2007 07:38 AM
problem of infinite loop sarah lee ASP.NET 1.0 and 1.1 Basics 19 December 14th, 2006 09:26 AM
while loop problem shoakat Classic ASP Databases 1 September 21st, 2004 03:44 PM





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