Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2005, 10:10 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default HOW TO: Display specified # of nodes

How can I set up a <xsl:for-each...> method that uses an <xsl:if...> statement to display specified number of nodesets?

I'm basically wanting to display a set of data from an XML doc in a 3-column display using CSS positioning using <div> tags.

This is how I'd like it to be set up, but I'm not sure how to accomplish the "COUNT" of the nodesets:

Code:
<xsl:for-each select="root/element">
    <xsl:if test="COUNT <= '10'>
        <div id="columnA">
            <xsl:value-of select="childnode" />
        </div>
    </xsl:if>
    <xsl:if test="COUNT >= '11' and COUNT <= '20'>
        <div id="columnB">
            <xsl:value-of select="childnode" />
        </div>
    </xsl:if>
    <xsl:if test="COUNT >= '21' and COUNT <= '30'>
        <div id="columnC">
            <xsl:value-of select="childnode" />
        </div>
    </xsl:if>
</xsl:for-each>
Any & all help is appreciated. Thanks.

KWilliams
 
Old October 5th, 2005, 11:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Just use the position() function whereever you've written COUNT. And of course you need to escape "<" as "&lt;".

But it would be better to do three for-each loops:

<xsl:for-each select="(root/element)[position() &lt;= 10]">
  ...

etc.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 5th, 2005, 11:04 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great. Thanks for the information, the quick response, and the suggestion concerning the 3 for-each loops instead. I'll give it a try right now.

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to value in b/n nodes Swetha XSLT 1 May 20th, 2008 12:20 PM
How can I display parent & child nodes if XML .... vishnu108mishra ASP.NET 2.0 Basics 0 November 17th, 2007 07:45 AM
differentiating between two nodes RazoRmedia XSLT 4 February 9th, 2006 06:25 AM
Display nodes from xml nambati XSLT 2 September 17th, 2004 07:57 AM
How to display all nodes in my Network using VB 6 harini19 VB How-To 1 January 16th, 2004 10:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.