I'm not sure the whole approach is right but shouldn't the 'call-template 
name="loop"' be inside the for-each?
Joe
From: "Austin, Darrel" 
<Darrel(_dot_)Austin(_at_)courts(_dot_)state(_dot_)mn(_dot_)us>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: [xsl] Confused using a loop...
Date: Wed, 28 Mar 2007 09:36:55 -0500
Still working on the RSS transformation...
I had everything working, except that I realized I want to only grab x
number of elements instead of all matches. To do this, I think I need to
use a recursive template with a parameter. This is what I have (I've
removed the RSS tags to make the XSL clearer) but the problem is that it
does only loop 3 times as wanted, but my 'value-of' tags in my
'createItem' template are all null/blank. I'm not sure why.
=======================================================
<xsl:variable name="numberOfItemsToList" select="3"/>
<xsl:template match="/">
        <xsl:for-each select="//menuItem[pageID =
$pageID]/descendant-or-self::menuItem">
                <xsl:sort select="substring(lastUpdate,1,4)"
order="descending" /> <!-- year  -->
                <xsl:sort select="substring(lastUpdate,6,2)"
order="descending" /> <!-- month -->
                <xsl:sort select="substring(lastUpdate,9,2)"
order="descending" /> <!-- day   -->
        </xsl:for-each>
        <xsl:call-template name="loop"/>
</xsl:template>
<xsl:template name="loop">
        <xsl:param name="i">1</xsl:param>
        <xsl:choose>
        <xsl:when test="$i <= $numberOfItemsToList">
                <xsl:call-template name="createItem" />
                <xsl:call-template name="loop">
                        <xsl:with-param name="i" select="$i + 1"/>
                </xsl:call-template>
        </xsl:when>
        </xsl:choose>
</xsl:template>
<xsl:template name="createItem">
        <xsl:value-of select="browserTitle" />
        Page last updated: <xsl:value-of select="lastUpdate" />
        <a
href="http://www.mncourts.gov{$linkPrefix}?page={pageID}">http://www.mnc
ourts.gov<xsl:value-of select="$linkPrefix"/>?page=<xsl:value-of
select="pageID"/></a>
        <xsl:value-of select="lastUpdate" />
</xsl:template>
=======================================================
Sample XML:
<menuItems>
   <menuItem>
      <pageID>938</pageID>
      <browserTitle>Home Page</browserTitle>
      <lastUpdate>2006/06/12</lastUpdate>
      <menuItem>
         <pageID>998</pageID>
         <browserTitle>District Administration</browserTitle>
         <lastUpdate>2006/06/06</lastUpdate>
      </menuItem>
      <menuItem>
         <pageID>1342</pageID>
         <browserTitle>Employment</browserTitle>
         <lastUpdate>2006/07/13</lastUpdate>
      </menuItem>
   ...
-Darrel
--~------------------------------------------------------------------
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>
--~--