Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Keeping count/position of table rows

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
Tamre
Asked:
Tamre
  • 3
  • 3
1 Solution
 
sdussingerCommented:
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
 
TamreAuthor Commented:
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
 
sdussingerCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
TamreAuthor Commented:
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
 
TamreAuthor Commented:
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
 
sdussingerCommented:
Glad I could help. If you run into another question, post it here, and I'll help if I can.

--Steve
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now