Solved

xml and stylesheet Loop Command

Posted on 2013-06-23
7
205 Views
Last Modified: 2013-07-04
I am brand new to xml and am making slow progress.

I have the attached xml Invoice and Stylesheet that I am trying to marry up.  It is now at the stage where is is bringing back most of the details, however it is only returning the first line of the invoice.

In the attached example there are 2 lines, but only detail of the first is being displayed.  I have tried using the </xsl:for-each> command but all I am getting is a blank screen.

Is this the right command to use?  Where should I be placing it?
2406001.XML
CBS.XSL
0
Comment
Question by:sochionnaitj
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39270408
you had an issue with the prefixes, use si: allover
CBS-fixed2.xsl
0
 

Author Comment

by:sochionnaitj
ID: 39273153
Thanks, but still only 1 Invoice detail line is appearing.  Is it the </xsl:for-each> command that I need to use to get the second detail line to appear (from the xml example)?  I have tried adding it in to no avail
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39273187
You need a for-each there indeed...
(around line 200)

Note that also the context then changes
Here is how that wtr> construct should be

            <xsl:for-each select="si:Details/si:Detail">
            <tr>
              <td><xsl:value-of select='si:LineNo'/></td>
              <td><xsl:value-of select='si:Products/si:Quantity'/></td>
              <td>F12406</td>
              <td><xsl:value-of select='si:Products/si:SellerProductDescr'/></td>
              <td></td>
              <xsl:choose>
		    <xsl:when test="/si:ABWInvoice/si:Invoice/si:Header/si:InvoiceType/@Code='INV'">
                </xsl:when>
                <xsl:otherwise><td></td></xsl:otherwise>
	        </xsl:choose>
              <td class='sectTitle'>Total Tax</td>
              <td>&#160;</td>
              <td class='summary'>
                <xsl:value-of select='si:Summary/si:TotalTax' />
                <xsl:if test='not(string-length(si:Summary/si:TotalTax))'>
                  <div class='warn'>Missing</div>
                </xsl:if>
              </td>
            </tr>
            </xsl:for-each>

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:sochionnaitj
ID: 39273223
I have added it it as below, the third tdL <td>F12406</td>, appears twice, once for each line.  but the Line No, Quantity and Product Description are now blank.  What could be causing these to be omitted?

<xsl:for-each select="si:Details/si:Detail">
            <tr>
              <td><xsl:value-of select='si:Details/si:Detail/si:LineNo'/></td>
              <td><xsl:value-of select='si:Details/si:Detail/si:Products/si:Quantity'/></td>
              <td>F12406</td>
              <td><xsl:value-of select='si:Details/si:Detail/si:Products/si:SellerProductDescr'/></td>
              <td></td>
              <xsl:choose>
                <xsl:when test="/si:ABWInvoice/si:Invoice/si:Header/si:InvoiceType/@Code='INV'">
                </xsl:when>
                <xsl:otherwise><td></td></xsl:otherwise>
              </xsl:choose>
              <td class='sectTitle'>Total Tax</td>
              <td>&#160;</td>
              <td class='summary'>
                <xsl:value-of select='si:Summary/si:TotalTax' />
                <xsl:if test='not(string-length(si:Summary/si:TotalTax))'>
                  <div class='warn'>Missing</div>
                </xsl:if>
              </td>
            </tr>
                  </xsl:for-each>
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 310 total points
ID: 39273474
You should have pasted the lines I copied...

The error is here
             <td><xsl:value-of select='si:Details/si:Detail/si:LineNo'/></td>

The for-each brings you in context of the node it visits
<xsl:for-each select="si:Details/si:Detail">
inside the for each your context is the si:Detail element

so you should not do
             <td><xsl:value-of select='si:Details/si:Detail/si:LineNo'/></td>
but
             <td><xsl:value-of select='si:LineNo'/></td>

as I did in the code snippet you should have used

I hope this helps
0
 

Author Closing Comment

by:sochionnaitj
ID: 39298858
Thank You
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39299246
welcome
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question