xsl-list
[Top] [All Lists]

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

2010-09-17 15:01:28
I have sample xml:

        <category name="mens_apparel" display_name="Mens">
                <info>
                        <keyword>C1</keyword>
                        <link>/category/mens_apparel</link>
                        <titletag></titletag>
                        <images>
                                <image/>
                        </images>
                        <metaDescription></metaDescription>
                </info>
                <category name="mens_shirts" display_name="Shirts">
                        <info>
                                <keyword>IHMTEE</keyword>
        
<link>/products/mens_apparel/mens_shirts</link>
                                <titletag></titletag>
                                <images>
                                        <image/>
                                </images>
                                <metaDescription></metaDescription>
                        </info>
                </category>
                <category name="mens_sweatshirts"
display_name="Sweatshirts">
                        <info>
                                <keyword>IHMSWEAT</keyword>
        
<link>/products/mens_apparel/mens_sweatshirts</link>
                                <titletag></titletag>
                                <images>
                                        <image/>
                                </images>
                                <metaDescription></metaDescription>
                        </info>
                </category>
                <category name="mens_outerwear"
display_name="Outerwear">
                        <info>
                                <keyword>IHMOUT</keyword>
        
<link>/products/mens_apparel/mens_outerwear</link>
                                <titletag></titletag>
                                <images>
                                        <image/>
                                </images>
                                <metaDescription></metaDescription>
                        </info>
                </category>
                <category name="mens_accessories"
display_name="Accessories">
                        <info>
                                <keyword>IHMACC</keyword>
        
<link>/products/mens_apparel/mens_accessories</link>
                                <titletag></titletag>
                                <images>
                                        <image/>
                                </images>
                                <metaDescription></metaDescription>
                        </info>
                </category>
        </category>

And on every 4th subcategory I just want to set the margin-right: 0px.

Here is the XSL and my attempt.

Please guide me.

 <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>
--~--

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