Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display a fixed number of elements? 2

Status
Not open for further replies.

BeckD

Programmer
Apr 16, 2002
53
0
0
GB
Hi

I have an xml page which is database driven (asp). In my xsl page I only want to display the first 5 articles. Something like:

--xml page
<page>
<article>
<title>Test</title>
<body>blah blah blah labhabl hb</body>
</article>
<article>
<title>Test</title>
<body>blah blah blah labhabl hb</body>
</article>
<article>
<title>Test</title>
<body>blah blah blah labhabl hb</body>
</article>
<article>
<title>Test</title>
<body>blah blah blah labhabl hb</body>
</article>
--etc
</page>

--xsl - this bit only wants to select the first 5 articles although the code I've put doesn't work
<xsl:for-each select=&quot;/page/article[count = 5]&quot;>
<xsl:value-of select=&quot;title&quot; />
</xsl:for-each>

If you get my drift...

I have found an example which works with the working draft xsl namespace, but it won't work with the namespace I'm using (<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; and I don't really want to go backwards and use the working draft. This code is:

<xsl:choose>
<xsl:when expr=&quot;childNumber(this) > 5&quot;></xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;/page/article/title&quot; />
</xsl:eek:therwise>
</xsl:choose>

Grateful in advance for any comments/suggestions...
 
<xsl:for-each select=&quot;/page/article[position()<5]&quot;>
<xsl:value-of select=&quot;title/>
</xsl:for-each>
<xsl:for-each select=&quot;/page/article[position()>=5]&quot;>
<br/>
</xsl:for-each>
mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top