Need (again) some help on paginate a rather simple xml table data displaying only one record at a time, but as a stacked nodes like this:
|================|
| FNAME |
|----------------|
| Smith |
|----------------|
| LNAME |
|----------------|
| Milton |
|----------------|
| AGE |
|----------------|
| 44 |
|----------------|
| ADDRESS |
|----------------|
|5th smmr st,mntb|
|----------------|
| CITY |
|----------------|
| Portland |
|================|
<< < pag 1/6 > >>
=================
and with "first prev page next last" links at a bottom of a table for one to advance over next prev first and last record; as it is showcased up there in a picture. Those <a href links are, of course, bound by few js functions which I also showed further down...
This is rather an old question raised up here a couple of years ago:
XML table columns vertically stacked within rows
but hasn't got those moving around links ...
Xml file is as follows:
<persns>
<prsn>
<fname>Smith</fname>
<lname>Milton</lname>
<age>44</age>
<addrss>5th summer st, mntb</addrss>
<city>Portland</city>
</prsn>
<prsn>
<fname>Ken</fname>
<lname>Jackson</lname>
<age>37</age>
<addrss>19th Penfield ave, brtcl</addrss>
<city>Kelowna</city>
</prsn>
<prsn>
<fname>Susan</fname>
<lname>Arkland</lname>
<age>48</age>
<addrss>34th Mansfield st, sgtp</addrss>
<city>Raleigh</city>
</prsn>
<prsn>
<fname>Smith</fname>
<lname>Milton</lname>
<age>44</age>
<addrss>5th summer st, mntb</addrss>
<city>Portland</city>
</prsn>
<prsn>
<fname>Ken</fname>
<lname>Jackson</lname>
<age>37</age>
<addrss>19th Penfield ave, brtcl</addrss>
<city>Kelowna</city>
</prsn>
<prsn>
<fname>Susan</fname>
<lname>Arkland</lname>
<age>48</age>
<addrss>34th Mansfield st, sgtp</addrss>
<city>Raleigh</city>
</prsn>
</persns>
and xslt is also like this:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:variable name="pags" select="count(//prsn)"/>
<xsl:template match="prsns">
<xsl:apply-templates select="prsn[position()]"/>
</xsl:template>
<xsl:template match="prsn">
<xsl:variable name="pag" select="position()"/>
<table border="1" id='content{$pag}' width="170" height="170" style="text-align:center;margin-left:297px; border-collapse:collapse; margin-top:22px;">
<tr><th>Frst Name</th></tr><tr><td><xsl:value-of select="."/></td></tr>
<tr><th>Last Name</th></tr><tr><td><xsl:value-of select="."/></td></tr>
<tr><th>Age</th></tr> <tr><td><xsl:value-of select="."/> </td></tr>
<tr><th>Address</th></tr> <tr><td><xsl:value-of select="."/> </td></tr>
<tr><th>City</th></tr><tr><td><xsl:value-of select="."/></td></tr>
<!-- pagination area -->
<tr>
<td colspan="4" style="background-color: #FCF3CF"> <!-- #FCF3CF -->
<div class="bpagn" style="margin-top:3.99px;height:21px;margin-left:23px; margin-right:30px">
<xsl:choose>
<xsl:when test="$pag = 1">
<xsl:text>pag</xsl:text><xsl:text> </xsl:text>
<xsl:value-of select="$pag"/>
<xsl:value-of select="'/'"/>
<xsl:value-of select="$pags"/>
<xsl:text> </xsl:text>
<!--<xsl:value-of select="''"/> -->
<a href="#{$pag+1}" onclick="nextPage({$pag+1})">›</a> <!-- > -->
<xsl:text> </xsl:text>
<a href="#{$pags}" onclick="lastPage({$pags})">»</a> <!-- >> -->
</xsl:when>
<xsl:when test="$pag = $pags">
<xsl:value-of select="' '"/>
<a href="#{$pags - ($pags -1)}" onclick="firstPage({$pags - ($pags -1)})">«</a> <!-- << -->
<a href="#{$pag - 1}" onclick="prevPage({$pag - 1})">‹</a> <!-- < -->
<xsl:text> </xsl:text> <xsl:text>pag</xsl:text>
<xsl:value-of select="' '"/>
<xsl:value-of select="$pag"/>
<xsl:value-of select="'/'"/>
<xsl:value-of select="$pags"/>
</xsl:when>
<xsl:otherwise>
<a href="#" onclick=" ">«</a> <!-- << -->
<a href="#{$pag - 1}" onclick="prevPage({$pag - 1})">‹</a> <!-- < -->
<xsl:text>pag</xsl:text>
<xsl:value-of select="' '"/>
<xsl:value-of select="$pag"/>
<xsl:value-of select="'/'"/>
<xsl:value-of select="$pags"/>
<xsl:value-of select="' '"/>
<a href="#{$pag+1}" onclick="nextPage({$pag+1})">›</a> <!-- > -->
<a href="#" onclick="">»</a> <!-- >> -->
</xsl:otherwise>
</xsl:choose>
</div>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
I've got also a small js script through which paging advance is employed:
function nextPage(num)
{
document.getElementById("content"+num).style.display=""
num--
document.getElementById("content"+num).style.display="none"
}
function prevPage(num)
{
document.getElementById("content"+num).style.display=""
num++
document.getElementById("content"+num).style.display="none"
}
function lastPage(num)
{
document.getElementById("content"+num).style.display=""
num = num-(num-1) //2
document.getElementById("content"+num).style.display="none"
}
function firstPage(num)
{
document.getElementById("content"+num).style.display=""
num += num + num // 2 (num-1)
document.getElementById("content"+num).style.display="none"
}
Of course all these goes through a some index.html where everything should be displayed over the web. Got a couple of problems though:
- xslt stylesheet's condition is wrong: <xsl:template match="prsns"> <xsl:apply-templates select="prsn[position()]"/> </xsl:template>
- and also individual table cells displaying is also wrong