内容查询Web部件样式,隔行变色。

来源:互联网 发布:轩辕剑神骑进阶数据 编辑:程序博客网 时间:2024/06/06 02:12

首先要修改ContentQueryMain.xsl文件,在OuterTemplate.CallItemTemplate节点下修改
<xsl:otherwise>
                <xsl:apply-templates select="." mode="itemstyle">
                <xsl:with-param name="CurPos" select="$Position" />
                </xsl:apply-templates>
</xsl:otherwise>

然后就可以在ItemStyle.xsl文件中使用这个CurPos参数取得行号了
<xsl:template name="KXLF" match="Row[@Style='KXLF']" mode="itemstyle">
   <xsl:param name="CurPos" />
   <xsl:variable name="SafeImageUrl">
      <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
        <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="SafeLinkUrl">
      <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="DisplayTitle">
      <xsl:call-template name="OuterTemplate.GetTitle">
        <xsl:with-param name="Title" select="@Title"/>
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="LinkTarget">
      <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
    </xsl:variable>


<xsl:choose>
      <xsl:when test="$CurPos mod 2 = 1">
      
  <table cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#FFFFFF">
          <tr height="18px">
            <td width="3px"></td>
            <td width="5px">
              <img src="/_Layouts/Bingo/Images/li_img.gif"></img>
            </td>
            <td width="3px"></td>
            <td width="*">
              <a href="{$SafeLinkUrl}" target="_blank" title="{@SorD}">
                <acronym title="{$DisplayTitle}">
                  <font color="#232D50">
                    1<xsl:value-of select="substring($DisplayTitle,1,11)"/>...
                  </font>
                </acronym>
              </a>
            </td>
            <td width="80px" align="center" style="white-space:nowrap;overflow:hidden;" >
              <nobr>
                <xsl:value-of select="substring-before(@Created,' ')"/>
              </nobr>
            </td>
          </tr>
        </table>      </xsl:when>
      <xsl:otherwise>

        <table cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#e3efff">
          <tr height="18px">
            <td width="3px"></td>
            <td width="5px">
              <img src="/_Layouts/Bingo/Images/li_img.gif"></img>
            </td>
            <td width="3px"></td>
            <td width="*">
              <a href="{$SafeLinkUrl}" target="_blank" title="{@SorD}">
                <acronym title="{$DisplayTitle}">
                  <font color="#232D50">
                    2<xsl:value-of select="substring($DisplayTitle,1,11)"/>...
                  </font>
                </acronym>
              </a>
            </td>
            <td width="80px" align="center" style="white-space:nowrap;overflow:hidden;" >
              <nobr>
                <xsl:value-of select="substring-before(@Created,' ')"/>
              </nobr>
            </td>
          </tr>
        </table>
              </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

原创粉丝点击