xsl-list
[Top] [All Lists]

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

2010-09-20 11:11:17
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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>