[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] for-each within a for-each?


Subject: RE: [xsl] for-each within a for-each?
From: "Yates, Danny (ANTS)" <danny.yates@xxxxxxxxxx>
Date: Thu, 6 Mar 2003 16:47:23 -0000

Hi,

It's difficult to understand what layout you want, but see the attached
file. Also, if I may offer a couple of suggestions:

1) Long names in XML are good. Long names anywhere are good. They are
   clear and informative. But try and stay away from caps. They make
   things very difficult to understand. Look at the example that XSL
   sets.

2) Try and get out of thinking about how to process things and think
   more about describing what you want in the output rather than how
   to generate the output. The stylesheet I've included is heading
   that way.

3) I can't comment on the validity of your HTML - I don't know HTML.
   But I've tidied a few obvious things!

4) Generally accepted practice is to start with a static HTML page
   that has the layout you want, and once you have that, you have
   something to aim for with your XSLT.

That said, here's a stylesheet which shows all the information in
your XML document. If you need any pointers understanding how it
works, just shout...

Dan.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="POR">
    <html>
      <body>
        <table border="4" width="100%" valign="TOP" cellpadding="5">
          <colgroup align="CENTER">
            <th>LINE</th>
            <th>QUANTITY</th>
            <th>UOM</th>
            <th>PART NUMBER</th>
            <th colspan="2">SPEC/DATE</th>
            <th>PRICE</th>
            <th>BASIS OF UNIT PRICE</th>
          </colgroup>
      
          <xsl:apply-templates/>
        </table>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="ITEM_DETAIL">
    <tr>
      <td align="CENTER">
        <xsl:value-of select="PO_LINE_ITEM_NUM"/>
      </td>
      <td align="CENTER">
        <xsl:value-of select="QUANTITY"/>
      </td>
      <td align="CENTER">
        <xsl:value-of select="UNIT_OF_MEASURE_DESC"/>
      </td>
      <td align="CENTER">
        <xsl:value-of select="CUSTOMER_PART_NUM"/>
      </td>
      <td align="CENTER">
        <xsl:value-of select="UNIT_PRICE"/>
      </td>
      <td align="CENTER">
        <xsl:value-of select="BASIS_PRICE_DESC"/>
      </td>
    </tr>
    
    <xsl:apply-templates select="ITEM_DETAIL_NOTES"/>
    <xsl:apply-templates select="ITEM_MISC_CHARGES"/>
  </xsl:template>
  
  <xsl:template match="ITEM_DETAIL_NOTES">
    <tr>
      <td>&#160;</td>
      <td colspan="7">
        <xsl:value-of select="ITEM_DETAIL_NOTES_TEXT"/>
      </td>
    </tr>
  </xsl:template>
  
  <xsl:template match="ITEM_MISC_CHARGES">
    <tr>
      <td colspan="2">&#160;</td>
      <td colspan="5">
        <xsl:value-of select="ITEM_MISC_CHG_DESC"/>
      </td>
      <td>
        <xsl:value-of select="ITEM_MISC_CHG_AMT"/>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>

-----Original Message-----
From: Mike Rudolph [mailto:mrudolph@xxxxxxx]
Sent: 06 March 2003 16:01
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] for-each within a for-each?



All,

Newbie here.  Avidly reading FAQs, glossaries, etc.  I have a 'how-to'
question.  If you could point to a website addressing this particular
situation, that would be great.  I am not looking for anyone to write my
code.  Please forgive the layman's description that follows.  I may have
prostituted the term 'node' for my own purposes. :-)

I am using simple XSL to transform an XML files into HTML.  Several of these
have been completed by working from an original and making simple changes to
accommodate the new application.  The next one to complete is a purchase
order, and it's a head scratcher for this newbie.  The challenge is to
display multiple line item notes and charges (which can repeat) within a
line item node (which can also repeat - see sample XML input).  Basically
the line item level can contain this type of info:  Line item qty, price,
etc.); line item notes; line item charges; line item shipto.  Some of these
can repeat.  I already learned my tags are a bit long (tsk - old COBOL
habit).

</POR>
.
.
.
 <ITEM_DETAIL>
   <PO_LINE_ITEM_NUM>1</PO_LINE_ITEM_NUM>
   <QUANTITY>19</QUANTITY>
   <UNIT_OF_MEASURE_DESC>THOUSAND</UNIT_OF_MEASURE_DESC>
   <UNIT_PRICE>1050.18</UNIT_PRICE>
   <CUSTOMER_PART_NUM>06-77-9999</CUSTOMER_PART_NUM>
   <ITEM_DETAIL_NOTES>
     <ITEM_DETAIL_NOTES_TEXT>BOGUS LINE #1</ITEM_DETAIL_NOTES_TEXT>
   </ITEM_DETAIL_NOTES>
   <ITEM_DETAIL_NOTES>
     <ITEM_DETAIL_NOTES_TEXT>BOGUS LINE #2</ITEM_DETAIL_NOTES_TEXT>
   </ITEM_DETAIL_NOTES>
   <ITEM_MISC_CHARGES>
     <ITEM_MISC_CHG_DESC>SETUP CHARGE</ITEM_MISC_CHG_DESC>
     <ITEM_MISC_CHG_AMT>150.00</ITEM_MISC_CHG_AMT
   </ITEM_MISC_CHARGES>
   <ITEM_MISC_CHARGES>
     <ITEM_MISC_CHG_DESC>SHRINK WRAP CHARGE</ITEM_MISC_CHG_DESC>
     <ITEM_MISC_CHG_AMT>75.00</ITEM_MISC_CHG_AMT
   </ITEM_MISC_CHARGES>
 </ITEM_DETAIL>
   <PO_LINE_ITEM_NUM>2</PO_LINE_ITEM_NUM>
   <QUANTITY>20</QUANTITY>
   <UNIT_OF_MEASURE_DESC>THOUSAND</UNIT_OF_MEASURE_DESC>
   <UNIT_PRICE>1050.00</UNIT_PRICE>
   <CUSTOMER_PART_NUM>06-77-0000</CUSTOMER_PART_NUM>
   <ITEM_DETAIL_NOTES>
     <ITEM_DETAIL_NOTES_TEXT>BOGUS LINE #1</ITEM_DETAIL_NOTES_TEXT>
   </ITEM_DETAIL_NOTES>
   <ITEM_DETAIL_NOTES>
     <ITEM_DETAIL_NOTES_TEXT>BOGUS LINE #2</ITEM_DETAIL_NOTES_TEXT>
   </ITEM_DETAIL_NOTES>
   <ITEM_MISC_CHARGES>
     <ITEM_MISC_CHG_DESC>BOGUS CHARGE</ITEM_MISC_CHG_DESC>
     <ITEM_MISC_CHG_AMT>150.00</ITEM_MISC_CHG_AMT
   </ITEM_MISC_CHARGES>
   <ITEM_MISC_CHARGES>
     <ITEM_MISC_CHG_DESC>BOGUS CHARGE</ITEM_MISC_CHG_DESC>
     <ITEM_MISC_CHG_AMT>75.00</ITEM_MISC_CHG_AMT
   </ITEM_MISC_CHARGES>
 </ITEM_DETAIL>
.
.
.
</POR>

I can display any and all line items using xsl:for-each but have trouble
when it comes to the nodes subordinate to the line item level (example:
notes, misc charges).  I can get the very first note by specifying it, but
no more than that.  Tried all manners of putting another xsl:for-each within
the one shown, but that did not work.  Now that you know the situation, can
you point me to a FAQ or website which might handle this.


     <TABLE BORDER="4" WIDTH="100%" VALIGN="TOP" CELLPADDING="5">
     	  <COLGROUP
ALIGN="CENTER"><TH>LINE</TH><TH>QUANTITY</TH><TH>UOM</TH>
     	  <TH>PART NUMBER</TH><TH COLSPAN="2">SPEC/DATE</TH>
     	  <TH>PRICE</TH><TH>BASIS OF UNIT PRICE</TH></COLGROUP>
     	    <TR>
     	      <xsl:for-each select="POR/ITEM_DETAIL" >
     	      <TR><TD ALIGN="CENTER"><xsl:value-of select="PO_LINE_ITEM_NUM"
/></TD>
              <TD ALIGN="CENTER"><xsl:value-of select="QUANTITY" /></TD>
              <TD ALIGN="CENTER"><xsl:value-of select="UNIT_OF_MEASURE_DESC"
/></TD>
     	        <TD ALIGN="CENTER"><xsl:value-of select="CUSTOMER_PART_NUM"
/></TD>
     	        <TD ALIGN="CENTER"><xsl:value-of select="UNIT_PRICE" /></TD>
     	        <TD ALIGN="CENTER"><xsl:value-of select="BASIS_PRICE_DESC"
/></TD></TR>

              <looking for technique to display notes and charges for the
line item>

              </xsl:for-each>
            </TR>
     </TABLE>


----------

Mike Rudolph - EDI Coordinator
Green Bay Packaging Inc.
Phone: 920.433.5426
Fax:   920.438.5426
Email: mrudolph@xxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


***************************************************************************
This communication (including any attachments) contains confidential information.  If you are not the intended recipient and you have received this communication in error, you should destroy it without copying, disclosing or otherwise using its contents.  Please notify the sender immediately of the error.

Internet communications are not necessarily secure and may be intercepted or changed after they are sent.  Abbey National Treasury Services plc does not accept liability for any loss you may suffer as a result of interception or any liability for such changes.  If you wish to confirm the origin or content of this communication, please contact the sender by using an alternative means of communication.

This communication does not create or modify any contract and, unless otherwise stated, is not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 2 Triton Square, Regents Place, London NW1 3AN.  Registered in England under Company Registration Number: 2338548.  Regulated by the Financial Services Authority (FSA).
***************************************************************************


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords