0

我在表中设置固定行数时遇到问题。我用类似的代码创建了这个表:

<xsl:for-each select="DBData/tabulka1/Row[position() &lt; 14]">
      <tr>
             <td><xsl:value-of select="ODESILATEL"/></td>
             <td><xsl:value-of select="PREDMET"/></td>
             <td align="right" class="sOkrajem"></td>
      </tr>
</xsl:for-each>

而且我需要将行数固定为 15,即使我得到一些记录。

例如,如果我从数据库中只得到 13 行,那么左边的两行将是空的,但会在那里。为了更好地理解,这里是图片:http: //imageshack.us/photo/my-images/692/tabulkar.png/

如果需要,我可以编辑我的 SQL 代码。

感谢您的所有建议。很抱歉代表我的问题。

编辑。我的代码的更广泛示例:

我在表中设置固定行数时遇到问题。我用类似的代码创建了这个表:

<xsl:for-each select="DBData/tabulka1/Row[position() &lt; 14]">
      <tr>
             <td><xsl:value-of select="ODESILATEL"/></td>
             <td><xsl:value-of select="PREDMET"/></td>
             <td align="right" class="sOkrajem"></td>
      </tr>
</xsl:for-each>

而且我需要将行数固定为 15,即使我得到一些记录。

例如,如果我从数据库中只得到 13 行,那么左边的两行将是空的,但会在那里。为了更好地理解,这里是图片:http: //imageshack.us/photo/my-images/692/tabulkar.png/

如果需要,我可以编辑我的 SQL 代码。

感谢您的所有建议。很抱歉代表我的问题。

编辑。我最近使用代码的更广泛示例:

<?xml version="1.0" encoding="windows-1250"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="RolesPath" select="'%RolesPath%'"/>
  <xsl:decimal-format decimal-separator=","
                      grouping-separator="&#160;"/>

  <xsl:include href="%RolesPath%\_foot.xsl" />
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">


      <head>
        <meta name="lang" content="cs" />
        <meta http-equiv="Content-Type" content="text/xml; charset=windows-1250" />
        <meta name="copyright" content="© 2009-2010 Flores" />
        <link rel="stylesheet" type="text/css" href="style.css" />

      </head>
      <body class ="teloBezObrazku">
        <table width="95%" class="tabulka">
          <th colspan="3" class="nadpis">Vzkazy</th>
          <xsl:variable name="numRows" select="15" />
          <xsl:variable name="rows" select="DBData/tabulka1/Row" />
          <xsl:apply-templates select="$rows[position() &lt;= $numRows]" />
          <xsl:call-template name="AddRows">
            <xsl:with-param name="numRows" select="$numRows - count($rows)" />
          </xsl:call-template>
        </table>
        <span style="position: absolute; bottom: 10;">
          &#160;&#160;<a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS">Otevřít vše...</a><b class="cara">|</b>&#160;
          <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS,0,DoNewOnly">Nový...</a>
        </span>
        <xsl:call-template name="footer">
          <xsl:with-param name="RolesPath" select="'%RolesPath%'"/>
        </xsl:call-template>
        </foot>
      </html>
  </xsl:template>
  <!-- Separate templates -->
  <xsl:template name="TableRow" match="tabulka1/Row">
    <tr>
      <td>
        <xsl:value-of select="self::Row/ODESILATEL"/>
      </td>
      <td>
        <xsl:value-of select="self::Row/PREDMET"/>
      </td>
      <td align="right" class="sOkrajem"></td>
    </tr>
  </xsl:template>

  <xsl:template name="AddRows">
    <xsl:param name="numRows" />
    <xsl:if test="$numRows > 0">
      <xsl:call-template name="TableRow" />

      <xsl:call-template name="AddRows">
        <xsl:with-param name="numRows" select="$numRows - 1" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

编辑。第一行可能会出错。

<xsl:template name="tabulka1 | tabulka1/Row" mode="row">
  <tr onmouseover="className='seda'" onmouseout="className='bila'" title="{OBSAH}" style="cursor:hand" xmlns="http://www.w3.org/1999/xhtml">
    <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS,0,DoShow;{ID}">
      <xsl:choose>
        <xsl:when test = "PRECTENO='N'">
          <td align="left" class="sOkrajem"><b><xsl:value-of select="self::Row/ODESILATEL"/></b></td>
            <td align="left" class="sOkrajem"><b><xsl:value-of select="self::Row/PREDMET"/></b></td>
            <td align="right" class="sOkrajem">
              <b><xsl:value-of select="self::Row/DATUM"/>&#160;<xsl:value-of select="self::Row/HODINY"/><xsl:value-of select="self::Row/MINUTY"/></b>
            </td>
          </xsl:when>
          <xsl:otherwise>
            <td align="left" class="sOkrajem"><xsl:value-of select="self::Row/ODESILATEL"/></td>
            <td align="left" class="sOkrajem"><xsl:value-of select="self::Row/PREDMET"/></td>
            <td align="right" class="sOkrajem">
              <xsl:value-of select="self::Row/DATUM"/>&#160;<xsl:value-of select="self::Row/HODINY"/><xsl:value-of select="self::Row/MINUTY"/>
            </td>
        </xsl:otherwise>
      </xsl:choose>
    </a>
  </tr>
</xsl:template>
4

1 回答 1

1

您应该能够像这样完成它(我省略了页脚部分,我无权访问):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="RolesPath" select="'%RolesPath%'"/>
  <xsl:decimal-format decimal-separator=","
                      grouping-separator="&#160;"/>
  <xsl:variable name="numRows" select="15" />

  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
      <head>
        <meta name="lang" content="cs" />
        <meta http-equiv="Content-Type" content="text/xml; charset=windows-1250" />
        <meta name="copyright" content="© 2009-2010 Flores" />
        <link rel="stylesheet" type="text/css" href="style.css" />

      </head>
      <body class ="teloBezObrazku">
        <xsl:apply-templates select="DBData/tabulka1" />

        <xsl:apply-templates select="DBData/tabulka2" />
        <span style="position: absolute; bottom: 10;">
          &#160;&#160;<a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS">Otevřít vše...</a><b class="cara">|</b>&#160;
          <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS,0,DoNewOnly">Nový...</a>
        </span>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="TableRows">
    <xsl:variable name="rows" select="Row" />
    <xsl:apply-templates select="$rows[position() &lt;= $numRows]" mode="row" />
    <xsl:call-template name="AddRows">
      <xsl:with-param name="numRows" select="$numRows - count($rows)" />
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="AddRows">
    <xsl:param name="numRows" />
    <xsl:if test="$numRows > 0">
      <xsl:apply-templates select="." mode="row" />

      <xsl:call-template name="AddRows">
        <xsl:with-param name="numRows" select="$numRows - 1" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template match="tabulka1">
    <table width="95%" class="tabulka" xmlns="http://www.w3.org/1999/xhtml">
      <tr>
        <th colspan="3" class="nadpis">Vzkazy</th>
      </tr>
      <xsl:call-template name="TableRows" />
    </table>
  </xsl:template>

  <xsl:template match="tabulka1 | tabulka1/Row" mode="row">
    <tr xmlns="http://www.w3.org/1999/xhtml">
      <td>
        <xsl:value-of select="self::Row/ODESILATEL"/>
      </td>
      <td>
        <xsl:value-of select="self::Row/PREDMET"/>
      </td>
      <td align="right" class="sOkrajem"></td>
    </tr>
  </xsl:template>

  <xsl:template match="tabulka2">
    <table width="95%" class="tabulka" xmlns="http://www.w3.org/1999/xhtml">
      <tr>
        <th colspan="2" class="nadpis">Other Table</th>
      </tr>
      <xsl:call-template name="TableRows" />
    </table>
  </xsl:template>

  <xsl:template match="tabulka2 | tabulka2/Row" mode="row">
    <tr xmlns="http://www.w3.org/1999/xhtml">
      <td>
        <xsl:value-of select="self::Row/ODESILATEL2"/>
      </td>
      <td>
        <xsl:value-of select="self::Row/PREDMET2"/>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>

在此输入 XML 上运行时:

<DBData>
  <tabulka1>
    <Row>
      <ODESILATEL>Hello</ODESILATEL>
      <PREDMET>1</PREDMET>
    </Row>
    <Row>
      <ODESILATEL>Ciao</ODESILATEL>
      <PREDMET>2</PREDMET>
    </Row>
    <Row>
      <ODESILATEL>Hi</ODESILATEL>
      <PREDMET>3</PREDMET>
    </Row>
    <Row>
      <ODESILATEL>Bonjour</ODESILATEL>
      <PREDMET>4</PREDMET>
    </Row>
  </tabulka1>
  <tabulka2>
    <Row>
      <ODESILATEL2>Konnnichiwa</ODESILATEL2>
      <PREDMET>1</PREDMET>
    </Row>
    <Row>
      <ODESILATEL2>Wazzap</ODESILATEL2>
      <PREDMET>2</PREDMET>
    </Row>
    <Row>
      <ODESILATEL2>Buenos dias</ODESILATEL2>
      <PREDMET>3</PREDMET>
    </Row>
  </tabulka2>
</DBData>

结果是:

<html xml:lang="cs" lang="cs" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="lang" content="cs" />
    <meta http-equiv="Content-Type" content="text/xml; charset=windows-1250" />
    <meta name="copyright" content="© 2009-2010 Flores" />
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body class="teloBezObrazku">
    <table width="95%" class="tabulka">
      <tr>
        <th colspan="3" class="nadpis">Vzkazy</th>
      </tr>
      <tr>
        <td>Hello</td>
        <td>1</td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td>Ciao</td>
        <td>2</td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td>Hi</td>
        <td>3</td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td>Bonjour</td>
        <td>4</td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align="right" class="sOkrajem" />
      </tr>
    </table>
    <table width="95%" class="tabulka">
      <tr>
        <th colspan="2" class="nadpis">Other Table</th>
      </tr>
      <tr>
        <td>Konnnichiwa</td>
        <td></td>
      </tr>
      <tr>
        <td>Wazzap</td>
        <td></td>
      </tr>
      <tr>
        <td>Buenos dias</td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
    </table>
    <span style="position: absolute; bottom: 10;">
        <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS">Otevřít vše...</a><b class="cara">|</b> 
      <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS,0,DoNewOnly">Nový...</a>
    </span>
  </body>
</html>
于 2013-03-15T15:18:33.273 回答