Re: [xsl] Hello - how do I use the count function properly?

Subject: Re: [xsl] Hello - how do I use the count function properly?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 20 Sep 2010 12:11:03 -0400
Dan,

The other issue here is your duplication of code, when the only difference between the two branches is the presence of the @style attribute in one.

Consider something like this:

<xsl:template match="category">
  <xsl:for-each select="child::category">
    <div class="cat_module">
      <xsl:if test="position() mod 4 = 0">
        <xsl:attribute name="style">
          <xsl:text>margin-right: 0px !important</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <h2>
       <a href="{descendant::link}">
        <xsl:value-of select="@display_name"/>
        <img src="{descendant::image}" alt=""/>
       </a>
      </h2>
      <a href="{descendant::link}">
       <span>Shop Now</span>
      </a>
     </div>
  </xsl:for-each>
 </xsl:template>

Cheers,
Wendell

At 04:01 PM 9/17/2010, you wrote:

 <xsl:template match="category">
  <xsl:for-each select="child::category">
   <xsl:choose>
    <xsl:when test="count(/child::category)=4 or
count(/child::category)=8">
     <div class="cat_module" style="margin-right: 0px !important">
      <h2>
       <a href="{descendant::link}">
        <xsl:value-of select="@display_name"/>
        <img src="{descendant::image}" alt=""/>
       </a>
      </h2>
      <a href="{descendant::link}">
       <span>Shop Now</span>
      </a>
     </div>
    </xsl:when>
    <xsl:otherwise>
     <div class="cat_module">
      <h2>
       <a href="{descendant::link}">
        <xsl:value-of select="@display_name"/>
        <img src="{descendant::image}" alt=""/>
       </a>
      </h2>
      <a href="{descendant::link}">
       <span>Shop Now</span>
      </a>
     </div>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
 </xsl:template>

Dan Acuff


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread