CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
【经验总结】不能实施并行处理的情况 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  XML/SOAP

思归在么,再帮我看看呀

楼主newmung(迷途浪人)2002-06-25 18:06:31 在 Web 开发 / XML/SOAP 提问

上次的问题呀在控制列数的时候,当前元素占多少列放在子节点中了  
  <col>4</col>  
  <book>  
  <name>标题a</name>  
  <content>内容a</content>  
  </book>  
  <book>  
  <name>标题b</name>  
  <content>内容b</content>  
  </book>  
  <book>  
  <name>标题c</name>  
  <content>内容c</content>  
  </book>  
  <book>  
                                      <style   colspan="2"></style>    
  <name>标题d</name>  
  <content>内容d</content>  
  </book>  
  <book>  
                                      <style   colspan="3"></style>    
  <name>标题e</name>  
  <content>内容e</content>  
  </book>  
  <book>  
  <name>标题f</name>  
  <content>内容f</content>  
  </book>  
  <book>  
  <name>标题g</name>  
  <content>内容g</content>  
  </book>  
  我将对应脚本改成  
  var   sttrnod   =   nodeList[j].selectSingleNode("style");  
  if   (typeof(sttrnod)   !=   "object")  
          //var   attr   =   sttrnod.attributes.getNamedItem("colspan").text;  
            var   attr   =   sttrnod.getAttribute("colspan");  
  else  
            var   attr=1;  
  结果它就不能再换行了  
  感觉是attr没有得到值,是这样的吗?  
  我如果直接用nodeList[j].selectSingleNode("style").getAttribute("colspan");  
  在没有设置<style>节点的地方要报错  
  问题点数:0、回复次数:4Top

1 楼saucer(思归)回复于 2002-06-26 06:03:26 得分 0

try  
   
  <xsl:stylesheet   version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"  
  xmlns:user="urn:whatever"  
  exclude-result-prefixes="msxsl   user">  
  <msxsl:script   language="jscript"   implements-prefix="user">  
  <![CDATA[  
  var   g_nRowCount=0;  
  var   g_nColsCount=0;  
  var   oRows=null;  
   
  function   init(nodeList,   nColsPerRow)  
  {  
      g_nRowCount   =nodeList.length;  
      g_nColsCount   =nColsPerRow;  
   
      oRows=new   Array(g_nRowCount);  
      for   (var   i=0;   i   <   g_nRowCount;   i++)  
      {  
      oRows[i]   =   new   Array(3);  
      }  
   
      var   nRow=0,   j=0;  
      var   nCount=0,nStart,nEnd;  
   
      while   (j<g_nRowCount)  
      {  
      nStart   =   j;  
      nEnd   =   nStart;  
   
      nCount   =   0;  
          var   nOldCount;  
      do  
      {  
              nOldCount   =   nCount;  
              var   nInc   =   1;  
              var   style   =   nodeList[j].selectSingleNode("style");  
      if   (style)  
      {  
      var   attr   =   style.getAttribute("colspan");  
      if   (attr)  
          nInc   =   parseInt(attr);  
  }  
   
  nCount   +=   nInc;  
   
      if   (nCount   <=   g_nColsCount)  
      {  
      nEnd   =   j;  
      j++;  
      nOldCount   =   nCount;  
        }  
        else  
        {  
        if   (nStart   ==   j)  
            nOldCount   =   nCount;  
      break;  
      }  
   
      }   while   (j   <   g_nRowCount);  
   
            oRows[nRow][0]   =   nStart+1;  
            oRows[nRow][1]   =   nEnd+1;  
                oRows[nRow][2]   =   nOldCount;  
            nRow++;  
   
                j   =   nEnd   +   1;  
      }  
   
      return     nRow;  
  }  
   
  function   getValue(nRow,   nCol)  
  {  
      if   ((0   <=   nRow)   &&   (nRow<   g_nRowCount)   &&   oRows[nRow][nCol]   !=   null)  
            return   oRows[nRow][nCol];  
        else  
        return   -1;  
  }  
  function   getStart(nRow)  
  {  
        nRow--;  
        return   getValue(nRow,0);  
  }  
   
  function   getEnd(nRow)  
  {  
        nRow--;  
        return   getValue(nRow,1);  
  }  
   
  function   getWidth(nRow)  
  {  
        nRow--;  
        return   getValue(nRow,2);  
  }  
  ]]>  
  </msxsl:script>  
   
  <xsl:template   match="/">  
  <xsl:variable   name="ColsPerRow"   select="number(books/col)"   />  
  <html>  
  <body>  
  <table   border="1">  
  <xsl:variable   name="RowCount"   select="user:init(books/book,   $ColsPerRow)"   />  
  <xsl:for-each   select="books/book[position()   &lt;=   $RowCount]">  
      <xsl:variable   name="start"   select="user:getStart(position())"   />  
      <xsl:variable   name="end"   select="user:getEnd(position())"   />  
      <!--***<xsl:value-of   select="$start"   />:<xsl:value-of   select="$end"   />***-->  
      <xsl:if   test="$start   !=   -1">  
      <tr>  
      <xsl:for-each   select="/books/book[position()   &gt;=   $start   and   position()   &lt;=   $end]">  
      <td>  
      <xsl:if   test="style"><xsl:attribute   name="colspan"><xsl:value-of   select="style/@colspan"   /></xsl:attribute></xsl:if>  
      <xsl:value-of   select="name"   />:<xsl:value-of   select="content"   /></td>  
      </xsl:for-each>  
      <xsl:variable   name="CurWidth"   select="user:getWidth(position())"   />  
      <xsl:if   test="$CurWidth   &lt;   $ColsPerRow">  
          <xsl:for-each   select="(document('')//namespace::*)[position()   &lt;=   $ColsPerRow   -   $CurWidth]">  
      <td><xsl:text>&#160;</xsl:text></td>  
          </xsl:for-each>  
      </xsl:if>  
      </tr>  
      </xsl:if>  
  </xsl:for-each>  
  </table>  
  </body>  
  </html>  
  </xsl:template>  
  </xsl:stylesheet>  
   
   
  Top

2 楼newmung(迷途浪人)回复于 2002-06-26 09:41:35 得分 0

nOldCount   有什么作用?  
  if(style)  
    if(attr)  
  如果style存在返回true,如果attr不存在返回FLASE?  
   
  CurWidth是得到每一行结束的ID号吗?  
  下面用到NAMESPACE,有什么用么?能给我说说吗?  
  哪个脚本有点注释就好了  
  <xsl:for-each   select="(document('')//namespace::*)[position()   &lt;=   $ColsPerRow   -   $CurWidth]">  
   
  Top

3 楼saucer(思归)回复于 2002-06-26 18:28:42 得分 0

var   style   =   nodeList[j].selectSingleNode("style");  
  if   (style)   //如果"style"节点不存在,style变量的值是null,该判断语句不真  
  {  
      var   attr   =   style.getAttribute("colspan");  
      if(attr)   //如果"colspan"属性不存在,attr变量的值是null,该判断语句不真  
   
  $CurWidth是用来获取当前行的表格单元个数  
   
  <xsl:for-each   select="(document('')//namespace::*)[position()   &lt;=   $ColsPerRow   -   $CurWidth]">  
  <td><xsl:text>&#160;</xsl:text></td>  
  </xsl:for-each>  
   
  如果$CurWidth小于所设表格单元的总个数,则在其后添加只含&nbsp;的表格单元,我在这里偷懒了,没有用递归的方法添加表格单元,而是用一个循环语句,document('')//namespace::*   是获取本XSLT样式表中所有的namespace节点,估计其数量大于你所设的表格单元总个数,:-)Top

4 楼saucer(思归)回复于 2002-06-26 18:30:10 得分 0

nOldCount是在计算中用来记住当前行的表格单元个数Top

相关问题

  • 思归,帮帮我!
  • 思归,我需要你的帮助!!
  • 请思归帮忙
  • 思归,帮帮忙看一下我的问题?
  • 孟子E章,思归......各位大侠可以帮帮我吗
  • include 的问题!!!!!!!急(思归)(不贪) 再帮忙看看!!!
  • saucer(思归)请进``帮我看看这个问题``
  • 谢谢思归给我热心的帮助,请来领分!
  • 》》》》》》》》dotnet让我郁闷!思归帮忙解答一下!
  • 思归,我很笨啊,再问个问题!

关键词

  • 内容
  • 节点
  • sttrnod
  • 标题
  • attr
  • colspan
  • nodelist
  • selectsinglenode
  • getattribute
  • style

得分解答快速导航

  • 帖主:newmung

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
CSDN网站24小时值班电话:13552009689
Copyright © 2000-2009, CSDN.NET, All Rights Reserved
GongshangLogo