以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  求助,如何将空的信息也显示出来  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=8157)


--  作者:cheng_fy
--  发布时间:6/7/2004 12:21:00 PM

--  求助,如何将空的信息也显示出来
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="maxtest.xsl"?>
<BAPLIE>
 <SG5>
  <C1>
   <D1>7</D1>
   <D2>SEVENTH</D2>
  </C1>
 </SG5>
 <SG5>
  <C1>
   <D1>1</D1>
   <D2>FIRST</D2>
  </C1>
 </SG5>
 <SG5>
  <C1>
   <D1>3</D1>
   <D2>THIRD</D2>
  </C1>
 </SG5>
 <SG5>
  <C1>
   <D1>4</D1>
   <D2>FOURTH</D2>
  </C1>
 </SG5>
</BAPLIE>
我写的样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <xsl:template match="/">
  <HTML>
   <BODY>
    <table>
     <tr>
     <xsl:for-each select="BAPLIE/SG5">
      <xsl:if test="C1/D1='1'">
       <td>
       <xsl:value-of select="C1/D2"/>
       </td>
      </xsl:if>
     </xsl:for-each>
     <xsl:for-each select="BAPLIE/SG5">
      <xsl:if test="C1/D1='2'">
       <td>
       <xsl:value-of select="C1/D2"/>
       </td>
      </xsl:if>
     </xsl:for-each>
     <xsl:for-each select="BAPLIE/SG5">
      <xsl:if test="C1/D1='3'">
       <td>
       <xsl:value-of select="C1/D2"/>
       </td>
      </xsl:if>
     </xsl:for-each>
     </tr>
    </table>
   </BODY>
  </HTML>
 </xsl:template>
</xsl:stylesheet>
但D1=2无法显示,我要的结果是:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>FIRST</td>
    <td>&nbsp;</td>
    <td>THIRD</td>
    <td>FOURTH</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>SEVENTH</td>
  </tr>
</table>
--  作者:cheng_fy
--  发布时间:6/8/2004 12:06:00 PM

--  
各位兄弟,谁能帮我解决上面的问题,只要能得到表格所示的结果就行,但注意:SG5的数目是不定的。
--  作者:sam
--  发布时间:6/8/2004 2:00:00 PM

--  
比较烦,不知道是否符合要求?

<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <html>
   <head/>
   <body>
    <table border="3">
     <tr>
      <xsl:for-each select="//SG5">
       <xsl:sort data-type="number" order="ascending" select="C1/D1"/>
       <xsl:if test="position() &lt; number(C1/D1)">
        <xsl:variable name="xxx">
         <xsl:call-template name="before">
          <xsl:with-param name="pos" select="position()"/>
         </xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="fill">
         <xsl:with-param name="num" select="number(C1/D1) - $xxx"/>
        </xsl:call-template>
       </xsl:if>
       <td>
        <xsl:value-of select="C1/D2"/>
       </td>
      </xsl:for-each>
     </tr>
    </table>
   </body>
  </html>
 </xsl:template>
 <xsl:template name="fill">
  <xsl:param name="num" select="1"/>
  <xsl:if test="$num &gt; 1">
   <td>space</td>
   <xsl:variable name="temp" select="$num - 1"/>
   <xsl:call-template name="fill">
    <xsl:with-param name="num" select="$temp"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>
 <xsl:template name="before">
  <xsl:param name="pos" select="1"/>
  <xsl:for-each select="//SG5">
   <xsl:sort data-type="number" order="ascending" select="C1/D1"/>
   <xsl:if test="position() = $pos - 1">
    <xsl:value-of select="C1/D1"/>
   </xsl:if>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>


--  作者:cheng_fy
--  发布时间:6/12/2004 2:21:00 PM

--  
不行啊,space太多了,但还有要感谢sam,现在很少人象你这样热心了
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
39.063ms