[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Confused using a loop...
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|