[xsl] Confused using a loop...

Subject: [xsl] Confused using a loop...
From: "Austin, Darrel" <Darrel.Austin@xxxxxxxxxxxxxxxxxx>
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 =
		<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:call-template name="loop"/>

<xsl:template name="loop">
	<xsl:param name="i">1</xsl:param>
	<xsl:when test="$i &lt;= $numberOfItemsToList">
		<xsl:call-template name="createItem" />
		<xsl:call-template name="loop">
			<xsl:with-param name="i" select="$i + 1"/>

<xsl:template name="createItem">
	<xsl:value-of select="browserTitle" />
	Page last updated: <xsl:value-of select="lastUpdate" />
ourts.gov<xsl:value-of select="$linkPrefix"/>?page=<xsl:value-of
	<xsl:value-of select="lastUpdate" />

Sample XML:

      <browserTitle>Home Page</browserTitle>
         <browserTitle>District Administration</browserTitle>


Current Thread