Solved

Keeping count/position of table rows

Posted on 2001-07-14
6
297 Views
Last Modified: 2008-02-26
Hi,
Below is a piece of an xslt file, a single template for a table that will extend over many pages.  I also have some fixed items on the pages (not included here) so this table can only render x number of rows per page, then there will be a page break and the table will continue on the next page.  I'm not sure how to keep track of the  rows so that say 12 rows will print on page one, then page two will begin with row 13 and print another 12 rows, etc.  Do I use position(), do I need a param?  Any direction, would be appreciated. Thanks!


<xsl:template name="pagetable">
<table id="table1">
<caption><xsl:value-of select="/statement/accountInfo/acctnum"/>&#xa0;<!--whitespace between elements--><xsl:value-of select="/statement/accountInfo/accttitle"/></caption>

<caption id="caption2">
<xsl:value-of select="/statement/text"/>&#xa0;<xsl:value-of select="format-number(transactions/@beginBal,'#,##0.00DB;#,##0.00CR')"/></caption>

<xsl:for-each select="transactions/transaction">

<tr id="tr1">

<td width="65px" align="left"><xsl:value-of select="date"/>&#xa0;</td>
<td width="70px"><xsl:value-of select="long"/>&#xa0;</td>
<td width="70px"><xsl:value-of select="short"/>&#xa0;</td>
<td width="225px"><xsl:value-of select="description"/>&#xa0;</td>
<td width="50px" align="center"><xsl:value-of select="priceCode"/>&#xa0;</td>

<td width="160px" align="right">
<xsl:if test="substring(amount,1,1)!='-'">
<xsl:value-of select="format-number(amount,'#,##0.00')"/>&#xa0;</xsl:if></td>

<td width="160px" align="right">
<xsl:if test="substring(amount,1,1)='-'">
<xsl:value-of select="format-number(amount,'#,##0.00')"/>&#xa0;</xsl:if></td>

<td width="180px" align="right">
<xsl:choose>
<xsl:when test="position()=1">
<xsl:value-of select="format-number(amount+//@beginBal,'#,##0.00DB;#,##0.00CR')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number(amount+sum(preceding-sibling::transaction/amount)+//@beginBal,'#,##0.00DB;#,##0.00CR')"/>&#xa0;
</xsl:otherwise>
</xsl:choose>

</td>
</tr>
</xsl:for-each> <!--transactions/transaction-->
</table>
</xsl:template>
0
Comment
Question by:Tamre
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:sdussinger
Comment Utility
Let's see if I undertand your question. You have an XML file which you will run this transform over several times to display all of the rows in the XML file. For example, if you can display 12 rows at a time and your XML file contains 60 rows, you'll apply this template 5 times to produce 5 pages, each containing 12 rows. Is that a fair assessment?

If so, you probably need to do something like the following:

1) Pass two params to your XSLT. The starting index for this page, and the number of entries to process.

2) Use the position() operation in the body of your for-each loop to determine if the current position() is between the starting index and starting index + num entries.  If the index is within that range, then output the rows as you do in your current XSLT. Otherwise do nothing.

Hopefully, this description is clear enough to get you going. If not, let me know and I'll try to give you something more specific.

On the other hand, if my assessment of what you're trying to do is off-base, post some more details, and I'll try again.

--Steve
0
 

Author Comment

by:Tamre
Comment Utility
Steve--an excellent assessment.  I have been working on this, a step at a time. I've tried to put the recursion in to print ten rows...although it is not yet working.
Do you see anything that jumps out and screams error?  I'm not real coiomfortable with recusion yet--I program in C--this is a little new.  Anyway, I'm not sure if I am WAY off, or just a bit. It would help knowing. It seems like after row 10 it would stop, but it is printing all the rows in the xml file at this point.

You mentioned position(), also.  Would that be used to track the tables rows from page to page--or for anyother purpose?  Somehow it does need to know that it should print rows 1-10 on page one, and must begin with row 11 on page two. I have no way of knowing the total rows (transactions) in advance as it will vary.

I indented my param stuff.  Hopefully it will render that way.

Thanks for your help....Tamre


<xsl:template name="pagetable">
<table id="table1">
<caption><xsl:value-of select="/statement/accountInfo/acctnum"/>&#xa0;<!--whitespace between elements--><xsl:value-of select="/statement/accountInfo/accttitle"/></caption>

<caption id="caption2">
<xsl:value-of select="/statement/text"/>&#xa0;<xsl:value-of select="format-number(transactions/@beginBal,'#,##0.00DB;#,##0.00CR')"/></caption>


    <xsl:for-each select="transactions/transaction">

    <xsl:call-template name="rowcount">
    <xsl:with-param name="start-val" select="1"/>
    <xsl:with-param name="end-val" select="10"/>
    </xsl:call-template>


</xsl:for-each> <!--transactions/transaction-->
</table>
</xsl:template>

    <xsl:template name="rowcount">
    <xsl:param name="start-val" select="0"/>
    <xsl:param name="end-val" select="0"/>
    <xsl:if test="$start-val &lt;= $end-val">

<tr id="tr1">

<td width="65px" align="left"><xsl:value-of select="date"/>&#xa0;</td>
<td width="70px"><xsl:value-of select="long"/>&#xa0;</td>
<td width="70px"><xsl:value-of select="short"/>&#xa0;</td>
<td width="225px"><xsl:value-of select="description"/>&#xa0;</td>
<td width="50px" align="center"><xsl:value-of select="priceCode"/>&#xa0;</td>


<td width="160px" align="right">
<xsl:if test="substring(amount,1,1)!='-'">
<xsl:value-of select="format-number(amount,'#,##0.00')"/>&#xa0;</xsl:if></td>

<td width="160px" align="right">
<xsl:if test="substring(amount,1,1)='-'">
<xsl:value-of select="format-number(amount,'#,##0.00')"/>&#xa0;</xsl:if></td>


<td width="180px" align="right">
<xsl:choose>
<xsl:when test="position()=1">
<xsl:value-of select="format-number(amount+//@beginBal,'#,##0.00DB;#,##0.00CR')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number(amount+sum(preceding-sibling::transaction/amount)+//@beginBal,'#,##0.00DB;#,##0.00CR')"/>&#xa0;
</xsl:otherwise>
</xsl:choose>

</td>
</tr>

    <xsl:call-template name="rowcount">
    <xsl:with-param name="start-val" select="$start-val + 1"/>
    <xsl:with-param name="end-val"/>
    </xsl:call-template>
    </xsl:if>
    </xsl:template>
0
 
LVL 4

Accepted Solution

by:
sdussinger earned 150 total points
Comment Utility
OK. I'm kinda winging it here, since I don't have any way to run your stuff on my machine. But I noticed something which looks a little odd.  You mentioned using recursion to do your processing, and I noticed that you're calling the row-count template from within the row-count template.

My question is why?

You have a for-each loop running over all of the elements in sequence. Your row-count template should just determine if the element in question should be printed or not, print it if it should be, and then return. There should be no need to recurse, unless I misunderstood something in your earlier post.

I would try something like:

In the for-each loop, compare the position () of each element to the start and end indices of the items you want to display. If the position () is in the correct range, call the row-count template, passing the current transaction, and let the row-count template just process the current element. Remove all of the if-then stuff from row-count that has to do with determining if the element is in the correct range, and remove the recursive call back to row-count.

This should do what you want.  If it's not clear, send me the entire XSLT and an XML sample, and I'll work on it some more.

--Steve
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Tamre
Comment Utility
Steve--

Good question!!  Your help has been great.  I have this piece up and running.  Thanks to your keen eye and great comments.

As I continue along this project, I may have another question or two...I hope you'll be around.

Thanks again,  Tamre
0
 

Author Comment

by:Tamre
Comment Utility
Steve was very helpful.  Sometimes you get stuck on viewing something in one way and it is nice to have another pair of eyes to help you see it in another light.
0
 
LVL 4

Expert Comment

by:sdussinger
Comment Utility
Glad I could help. If you run into another question, post it here, and I'll help if I can.

--Steve
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now