This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: xslt transform sql into html tables for dhtml paging


Ok,

realizing my email was a bit wordy and not to the point... I wanted
to follow-up PLUS I solved the problem...

its a really cool solution - not sure how textbook to XSLT usage
it is... but it works and is pretty speedy and it uses templates instead
of trying to think procedurally through the problem - though I use alot
of variables to determine Record Totals and Page #'s and the Page Total
count for this set of records when divided by the variable set for 
determining how many recs to show per page/per table.

See XSLT code:
(note: I am using MSXML4 as parser/transform engine)


	<xsl:variable name="sqlrecords"
select="$sqldata/xml/rs:data/z:row"/>

	<xsl:variable name="cnstPageRec" select="'4'"/>		<---- **this
determines how many recs per page/table

	<xsl:variable name="pgTotal" select="round(count($sqlrecords) div
$cnstPageRec)"/>	

		<xsl:for-each select="$sqlrecords[position() &lt;=
$pgTotal]">

			<div>

				<xsl:attribute
name="id">page<xsl:number/></xsl:attribute>

				<xsl:variable name="currN"
select="position() - 1"/>

				<xsl:variable name="recStart">

					<xsl:value-of select="$currN *
$cnstPageRec"/>

				</xsl:variable>

				<xsl:variable name="recEnd"
select="$recStart + $cnstPageRec"/>	

				<xsl:call-template name="rows">   <----
**calls a template to build the rows for each page/table        
       
					<xsl:with-param name="rStart"
select="$recStart"/>  <---- **which node to start with

					<xsl:with-param name="rEnd"
select="$recEnd"/> <---- **which node to end with

				</xsl:call-template>
			
				<tr>	<---- **row at the bottom of each
page/table that states PAGE 1 of 3 | Total: 8 goals
					
					<td>
						Page <xsl:value-of
select="position()"/> of <xsl:value-of select="$pgTotal"/> 
						| Total: <xsl:value-of
select="count($sqlrecords)"/> goals	
					</td>

				</tr>

			</div>

		</xsl:for-each>	


I can add further clarification if anyone is interested,

David



-----Original Message-----
From: Kovach, Dave 
Sent: Wednesday, January 23, 2002 4:45 PM
To: 'xsl-list@lists.mulberrytech.com'
Subject: [xsl] xslt transform sql into html tables for dhtml paging


Hello all,

I am bringing back sql records as an xml document... each record
is a node element...

<rs>
	<rec field="" field="" field= ...etc...>
	<rec..>
	<rec..>
	<rec..>
	<rec..>
	<rec..>
	<rec..>
	<rec..>
</rs>

My goal is to implement "paging" using XSLT... and using CSS and DHTML to
hide and unhide
tables built from the xml depending on which Page link is clicked... xslt is
happening
on the server... transforming the data etc. into html tables and then using
DHTML on
the client to change the CSS visibility of each table/hiding the others. 
So its pure HTML to the client.

So on the server, the problem is after getting the nodeset how to determine
how many 
tables to build and then add in the rows per table... and use the FOR...EACH
xslt
statement to do this??? I sorta end up with nested FOR...EACH's and then
cant figure
how to go back to the outer FOR...EACH to build the next table.. with the
next set
of data that would comprise that table...

I would set an arbitrary variable to define how many records (xml nodes) to 
display "per page"... So, say I set:

recPerTable = 4

And then iterate over the nodeset... to have 2 tables (8 rec's above divided
by recPerTable = 2) built that then will have 2 links:

Page1
Page2

And clicking page1 will show table 1 and hides table 2
and clicking page2 will show table 2 and hide table 1 you
get the idea.

Reason for doing this is... I am bringing back the sql records in one 
fell swoop and dont need to go back to the server. I have the DHTML etc.
all built and use it for other things similar to this... my problem
is trying to use the FOR...EACH XSLT statement and not use it thinking
like a "procedural language" programmer...

XSLT problem is:

1. Need to build (per example above) 2 tables... then
2. Need to grab the first 4 nodes of <rs> and place them in first table
3. Need to grab the last 4 nodes of <rs> and place them in second table


How might you accomplish this? Any ideas? Thoughts or better ways to 
approach?


Thank you for your ideas and input,

David

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

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]