[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Confused using a loop...

Subject: Confused using a loop...
From: "Austin, Darrel" <Darrel.Austin@xxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Mar 2007 09:36:55 -0500
 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 &lt;= $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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.