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 November 19th, 2004, 08:38 PM
Registered User
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Walking the Tree

I'm trying to ensure all the shipment header and lines display in order. I've nested the application of templates of the child elements in the templates of the parent elements. I'm not getting my shipment lines to output at all. What is wrong with the code below? Any help would be appreciated.

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:output method="html" omit-xml-declaration="yes"/>
<!-- *********************************
****
****
-->
<xsl:template match="/">
    <xsl:apply-templates select="OrderShipments/OrderInformation"/>
    <xsl:apply-templates select="OrderShipments/Shipment/Header"/>
</xsl:template>
<!-- *********************************
****
****
-->
<xsl:template match="OrderInformation" xml-space="preserve">
  <table width="100%" cellpadding="2" cellspacing="0" border="0" bgcolor="black"><tr><td>
    <table width="100%" cellpadding="4" cellspacing="0" border="0">
      <tr>
        <td valign="top">
          <table cellpadding="2" cellspacing="0" border="0">
            <tr>
              <td valign="top"><b>Reference#xa;Number:#xa;</b></td>
              <td valign="top"><xsl:value-of select="Reference"/></td>
            </tr>
            <tr>
              <td valign="top"><b>Order#xa;Number:#xa;</b></td>
              <td valign="top"><xsl:value-of select="OrderNumber"/></td>
            </tr>
            <tr>
              <td valign="top"><b>PO/Req #:#xa;</b></td>
              <td valign="top"><xsl:value-of select="CustomerPO"/></td>
            </tr>
             <tr>
              <td valign="top"><b>Current Status:#xa;</b></td>
              <td valign="top"><xsl:value-of select="Status"/></td>
            </tr>
          </table>
        </td>
        <td align="right" valign="top">
          <table cellpadding="2" cellspacing="0" border="0">
            <tr>
              <td valign="top">
                <b>Requestor:#xa;</b>
              </td>
              <td valign="top">
                <xsl:value-of select="AppUser"/>#xa;
              </td>
            </tr>
            <tr>
              <td valign="top"><b>Order#xa;Date:#xa;</b></td>
              <td valign="top"><xsl:value-of select="OrderDate"/></td>
            </tr>
             <tr>
              <td valign="top"><b>Requested Ship Date:#xa;</b></td>
              <td valign="top"><xsl:value-of select="RequestedShipDate"/></td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </td></tr></table>
  <p><center><b>
    ***** SHIPMENT INFORMATION FOR THIS ORDER *****
  </b></center></p>
</xsl:template>


<xsl:template match="Header" xml-space="preserve">
  <table width="100%" cellpadding="2" cellspacing="0" border="0">
    <tr>
       <td bgcolor="black"><b>Shipment Information</b></td>
    </tr>
    <tr>
      <td>
          <table cellpadding="0" cellspacing="0" border="0">
            <tr>
              <td valign="top"><b>Shipment ID:</b>#xa;</td>
              <td valign="top"><xsl:value-of select="ShipmentID"/></td>
            </tr>
            <tr>
              <td valign="top"><b>Tracking Number(s):</b>#xa;</td>
              <td valign="top"><a href="/"><xsl:value-of select="TrackingNum"/></a></td>
            </tr>
            <tr>
              <td valign="top"><b>Current Status:</b>#xa;</td>
              <td valign="top"><xsl:value-of select="Status"/> (as of <xsl:value-of select="StatusDate"/>)</td>
            </tr>
            <tr>
              <td valign="top"><b>Carrier:</b>#xa;</td>
              <td valign="top"><xsl:value-of select="Carrier"/></td>
            </tr>
            <tr>
              <td valign="top"><b>Shipment Date:</b>#xa;</td>
              <td valign="top"><xsl:value-of select="DateShipped"/></td>
            </tr>
            <tr>
              <td valign="top"><b>Tracking URL:</b>#xa;</td>
              <td valign="top"><xsl:value-of select="TrackingURL"/></td>
            </tr>
          </table>
      </td>
    </tr>
  </table>
    <xsl:apply-templates select="OrderShipments/Shipment/Lines"/>
  <p/>#xa;
   <!--<xsl:for-each select="OrderShipments/Shipment/Lines">
   <xsl:apply-templates />
   </xsl:for-each> -->
</xsl:template>

<xsl:template match="Lines" xml-space="preserve">
<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="#999999">
      <table width="100%" cellpadding="2" cellspacing="1" border="1">
        <tr bgcolor="black">
          <td width="1%">#xa;</td>
          <td><b>Item#xa;Number</b></td>
          <td><b>Req.#xa;Ship#xa;Date</b></td>
          <td align="right"><b>Order Quantity</b></td>
          <td align="right"><b>*Ship Quantity</b></td>
        </tr>
        <xsl:apply-templates select="OrderShipments/Shipment/Lines/LineItem"/>
      </table>
    </td></tr></table>
    #xa;*Items that have not shipped will not appear
</xsl:template>
<xsl:template match="LineItem" xml-space="preserve">
  <tr>
    <td bgcolor="#E7E7D1" width="1%" rowspan="2" valign="top"><xsl:value-of select="position()"/></td>

    <td bgcolor="#E7E7D1" width="%49"><xsl:value-of select="Item"/></td>

    <td bgcolor="#E7E7D1" align="right" width="%16">
      <xsl:apply-templates select="OrderQuantity"/>#xa;
      <xsl:value-of select="SalesUnit"/>
    </td>
     <td bgcolor="#E7E7D1" width="%18"><xsl:value-of select="ShippedQuantity"/></td>
  </tr>
  <tr>
    <td bgcolor="#E7E7D1" width="50%" valign="top">
      <table border="0" cellpadding="0" cellspacing="0">
       <tr><td colspan="2" valign="top"><b>Description:</b>#xa;<xsl:value-of select="ItemDescription"/></td></tr>
           </table>
    </td>
 </tr>
</xsl:template>

<xsl:template match="ShippedQuantity" xml-space="preserve">
  <xsl:value-of select="format-number(., '#,###,###')"/>
</xsl:template>

<xsl:template match="OrderQuantity" xml-space="preserve">
  <xsl:value-of select="format-number(., '#,###,###')"/>
</xsl:template>

</xsl:stylesheet>


 
Old November 22nd, 2004, 03:12 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

Context problems:
-----------------
Notice in your header template: you've got
<xsl:apply-templates select="OrderShipments/Shipment/Lines"/>
but that applies it from the current context, meaning it looks for node:
OrderShipments/Shipment/Header/OrderShipments/Shipment/Lines
Not sure why you don't have this apply-templates in your main template.

Also <xsl:apply-templates select="OrderShipments/Shipment/Lines/LineItem"/> in your Lines template should just be <xsl:apply-templates select="LineItem"/>

Of if you want to reference the root node, use '/' in front eg. /OrderShipments/etc...
 
Old November 22nd, 2004, 06:32 PM
Registered User
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jkmyoung, thanks for your reply. I'm looking process in sequence from the XML document. The Order Information will occur only once in the document. The ShipmentHeader information will repeat and is the driving repeating element. The Lines and LineItems that are listed after a particular header should be outputted after that header.

Putting the <xsl:apply-templates select="OrderShipments/Shipment/Lines/LineItem"/> statement in main template will cause all my lines to be displayed after all the headers have been displayed. I'm obviously doing something else wrong, but I thought rules-based processing would be best for this. I'm wondering if I need to use for-each. Any Ideas? Thanks.

 
Old November 22nd, 2004, 06:46 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

oh ok, I assume you're grouping them by Shipment.
The top one would then be:
<xsl:apply-templates select="OrderShipments/Shipment>

and then match each shipment by adding:
<xsl:template match="Shipment">
  <xsl:apply-templates select="Header"/>
  <xsl:apply-templates select="Lines/LineItem"/>
</xsl:template>

 
Old November 22nd, 2004, 07:20 PM
Registered User
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jkmyoung, you're correct. I did change <xsl:apply-templates select="Lines/LineItem"/> to <xsl:apply-templates select="Lines"/> because I'm calling the LineItem template from the Lines template. This is giving me the response I desire. Thanks for your solution.









Similar Threads
Thread Thread Starter Forum Replies Last Post
Walking through walls qjay BOOK: Professional Microsoft Robotics Studio ISBN: 978-0-470-14107-6 2 July 11th, 2008 03:03 PM
i want to make a tree viren_balaut J2EE 2 September 12th, 2004 11:41 PM
how to make a tree viren_balaut Javascript 1 August 30th, 2004 03:05 PM
how to make a tree viren_balaut Java GUI 0 August 30th, 2004 07:31 AM
walking an axis in sorted (not document) order rich_unger XSLT 1 August 8th, 2003 12:43 AM





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