xsl-list
[Top] [All Lists]

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

2010-09-17 15:26:32
I don't think the count function does what you think it does.  The count 
function gives the number of nodes in the node-set you pass to it.  The 
position function is probably of more use to you in this case.

----- Original Message -----
From: Dan Acuff <dacuff(_at_)suresource(_dot_)com>
Date: Friday, September 17, 2010 1:01 pm
Subject: [xsl] Hello - how do I use the count function properly?
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com

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>
       
        <xsl:value-of 
select="@display_name"/>        <img src="{descendant::image}" alt=""/>
       
      </h2>
      
       <span>Shop Now</span>
      
     </div>
    </xsl:when>
    <xsl:otherwise>
     <div class="cat_module">
      <h2>
       
        <xsl:value-of 
select="@display_name"/>        <img src="{descendant::image}" alt=""/>
       
      </h2>
      
       <span>Shop Now</span>
      
     </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>
--~--



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