我在表格中设置固定行数时遇到问题。 我用这个代码创建了类似代码的表:
<xsl:for-each select="DBData/tabulka1/Row[position() < 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() < 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=" "/>
<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() <= $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;">
  <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS">Otevřít vše...</a><b class="cara">|</b> 
<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"/> <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"/> <xsl:value-of select="self::Row/HODINY"/><xsl:value-of select="self::Row/MINUTY"/>
</td>
</xsl:otherwise>
</xsl:choose>
</a>
</tr>
</xsl:template>
答案 0 :(得分: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=" "/>
<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;">
  <a href="abrasite:A4NHDUKJESG4PJAVPQJFMAE2PS">Otevřít vše...</a><b class="cara">|</b> 
<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() <= $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>