跨浏览器的xslt分页(二)

搞了一个星期,xslt分页终于在IE和opera上跑起来了,这周放到嵌入式设备上,玩完...
用的是嵌入式最高级的浏览器,也才相当于opera7的水平,根本不支持xmlDocument,郁闷至极。接着搞了两天也没弄好。早上转换了思路,重新baidu了一下,居然找到解决方法,调试一上午,终于搞定。xslt真是麻烦啊...
xsl文件:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:param name="size" select="2"/>

 <xsl:template match="rss/channel">
  <html>
  <HEAD>
  <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
  <title><xsl:value-of select="/rss/channel/title"/></title>
  <script>
  <![CDATA[
   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 onInitialize(){
    var i = 1;
    document.getElementById("content"+i).style.display = "";
   }

   function jumpPage(page,pages){
     var num=document.getElementById("jump"+page).value;
     if(num==""){alert("please enter page!!");return false;}
     for(i=1;i<=pages;i++){
       document.getElementById("content"+i).style.display="none";
       if(i==page){
        document.getElementById("jump"+i).value="";
       }
       if(i==num){
        document.getElementById("content"+i).style.display="";
       }
     }
   }

   function showPage(page,pages){
     var num=page;
     for(i=1;i<=pages;i++){
       document.getElementById("content"+i).style.display="none";
       if(i==page){
        document.getElementById("jump"+i).value="";
       }
       if(i==num){
        document.getElementById("content"+i).style.display="";
       }
     }
   }
  ]]>
  </script>
  </HEAD>


   <body  topmargin="0" leftmargin="0" bgcolor="#47A3AC" onload="onInitialize()">
    <xsl:apply-templates select="item[position() mod $size = 1]">
     <xsl:with-param name="pages" select="ceiling(count(item) div $size)"/>
    </xsl:apply-templates>
   </body>
  </html>
 </xsl:template>



 <xsl:template match="item">
 <xsl:param name="pages"/>
 <xsl:variable name="page" select="position()"/>
 <div name="content" id='content{$page}' style="display:none" title="content{$page}">
 <table  border="0" cellspacing="0" cellpadding="0" style="position: absolute; width: 204px; height: 33px; left: 72px; top:13px">
        <tr>
		<td align="left" colspan="2">
			<font color="#FAFAFA"><span style="text-decoration: none"><strong>当前栏目:
			<xsl:value-of select="/rss/channel/title"/></strong></span></font>
		</td>
        </tr>
</table>
<table  border="0" cellspacing="0" cellpadding="0" style="position: absolute; width: 600px; height: 313px; left: 25px; top:55px">
	<tr>
		<td align="left" colspan="2"> 			
			<font color="#FAFAFA"><span style="text-decoration: none"><strong>
			Feed地址:<xsl:value-of select="/rss/channel/link"/>
			</strong></span></font>
		</td>
	</tr>
	<tr>
		<td>
			<font color="#FAFAFA"><span style="text-decoration: none"><strong>当前Feed内容: </strong></span></font>
		</td>
	</tr>
   <xsl:for-each select="self::item | following-sibling::item[position() &lt; $size]">
	<tr>
			<td>
				<table width="300"  height="30" border="0"  cellspacing="1" cellpadding="0">
					<tr>
						<td align="left" valign="middle"  height="29">
							<a>   
							    <xsl:attribute name="href">
							    <xsl:value-of  select="link"/>
							    </xsl:attribute> 
							    <font color="blue"><span style="text-decoration: none"><strong>
							    <xsl:value-of select="title"/>   
							    </strong></span></font>
							</a>
						</td>
					</tr>
					<tr>
						<td align="left" valign="middle"  height="29">
						<font color="#FAFAFA"><span style="text-decoration: none"><strong>
							<xsl:value-of select="description"/>
						</strong></span></font>
						</td>
					</tr>
					<tr>
						<td align="left" valign="middle"  height="29">
						<font color="#FAFAFA"><span style="text-decoration: none"><strong>
							<xsl:value-of select="pubDate"/>
						</strong></span></font>
						</td>
					</tr>
				</table>
			</td>
			<td>
				<table width="300"  height="30" border="0"  cellspacing="1" cellpadding="0">
					<tr>
					<xsl:for-each  select="/rss/channel/image">
						<td align="left" valign="middle"  height="29">
						
							<img>   
							  <xsl:attribute   name="src"><xsl:value-of  select="/rss/channel/image/url"/></xsl:attribute>   
							</img>  
						</td>
					</xsl:for-each>
					</tr>					
				</table>
			</td>
	   </tr>
   </xsl:for-each>
    <tr>
    <td>
    <xsl:choose>
     <xsl:when test="$page = 1">   
      <a href="#{$page + 1}" onclick="nextPage({$page + 1})">
      <font color="blue"><span style="text-decoration: none"><strong>     下一页    </strong></span></font>
      </a>     
      <a href="#{$page + 1}" onclick="showPage({$pages},{$pages})">
      <font color="blue"><span style="text-decoration: none"><strong>     末页    </strong></span></font>
      </a>

     </xsl:when>

     <xsl:when test="$page = $pages">    
     <a href="#{$page + 1}" onclick="showPage(1,{$pages})">
      <font color="blue"><span style="text-decoration: none"><strong>     首页    </strong></span></font>
      </a>
      <a href="#{$page - 1}" onclick="prevPage({$page - 1})">
      <font color="blue"><span style="text-decoration: none"><strong>     上一页     </strong></span></font>
      </a>   
     </xsl:when>

     <xsl:otherwise>
      <a href="#{$page + 1}" onclick="showPage(1,{$pages})">
      <font color="blue"><span style="text-decoration: none"><strong>     首页    </strong></span></font>
      </a>
      <a href="#{$page - 1}" onclick="prevPage({$page - 1})">
      <font color="blue"><span style="text-decoration: none"><strong>     上一页    </strong></span></font>
      </a>   
      <a href="#{$page + 1}" onclick="nextPage({$page + 1})">
      <font color="blue"><span style="text-decoration: none"><strong>     下一页    </strong></span></font>
      </a>    
      <a href="#{$page + 1}" onclick="showPage({$pages},{$pages})">
      <font color="blue"><span style="text-decoration: none"><strong>     末页    </strong></span></font>
      </a>
     </xsl:otherwise>
    </xsl:choose>
   </td>
   </tr>
   <tr>
   <td>
      <font color="#FAFAFA"><span style="text-decoration: none"><strong>当前第<xsl:value-of select="$page" />页 </strong></span></font> 
      <font color="#FAFAFA"><span style="text-decoration: none"><strong>共<xsl:value-of select="$pages" />页</strong></span></font>
   </td>
   </tr>
   <tr>
  <td> 
  <font color="#FAFAFA"><span style="text-decoration: none"><strong>
  转到<input type="text" name="jump" id="jump{$page}" value="" size="2"/>页 <input type="button" value="go" onclick="jumpPage({$page},{$pages})"/>
  </strong></span></font>
  </td>
   <td>
  <a href="SearchGenreServlet">
  <font color="blue"><span style="text-decoration: none"><strong>
   返回</strong></span></font>
  </a>
  </td>
   </tr>
   </table>
   </div>
 </xsl:template>
</xsl:stylesheet>
 

你可能感兴趣的:(浏览器,IE,Opera,嵌入式,XSL)