Subject: RE: [xsl] Confused using a loop... From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx> Date: Wed, 28 Mar 2007 15:44:24 +0100 |
From: "Austin, Darrel" <Darrel.Austin@xxxxxxxxxxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Confused using a loop..., Austin, Darrel | Thread | RE: [xsl] Confused using a loop..., Austin, Darrel |
Re: [xsl] Confused using a loop..., David Carlisle | Date | RE: [xsl] Confused using a loop..., Austin, Darrel |
Month |