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 July 3rd, 2007, 02:50 PM
Registered User
 
Join Date: Jul 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT loop counting and breaking.

How can I do some simple loops in XSLT and make counter updates..
Heres what im' working on::

Code:
    <xsl:for-each select="events/event">
        <xsl:for-each select="dates/date">
            <xsl:variable name="firstDate" select="concat(substring($currentDate, 1,4),substring($currentDate, 6,2),substring($currentDate,9,2))"/>
            <xsl:variable name="secondDate" select="concat(substring(., 1,4),substring(., 6,2),substring(.,9,2))"/>
            <xsl:if test="$secondDate > $firstDate">
                <div class="event">
                    <div class="event_tout" id="event_tout4">
                        <script type="text/javascript">
                            pngpong.serveButtonPopup("event_tout4","images/vwe_tout3.png","images/vwe_tout3.png","http://www.dubwars.com/2007/index.htm","");
                        </script>
                    </div>
                    <div class="event_content">
                        <div class="event_header">
                            <div id="dub_wars" class="event_title text_blue"><a href="http://www.dubwars.com/2007/index.htm" target="_blank"><xsl:value-of select="../title" /></a></div>
                            <div class="event_location text_grey_dark"><xsl:value-of select="../location" /></div>
                        </div>
                        <div class="event_date text_grey_dark"><xsl:value-of select="." /></div>
                        <div class="event_body">
                            This is the only car show where you can take your V-dub in a closed course and drift, spin and burnout to your heart's content. They call it Hooliganism, we call it some of the most fun you can have in a VW.
                        </div>
                    </div>
                </div>
            </xsl:if>
        </xsl:for-each>
    </xsl:for-each>
This line::
<div class="event_tout" id="event_tout4">
                        <script type="text/javascript">
                            pngpong.serveButtonPopup("event_tout4","images/vwe_tout3.png","images/vwe_tout3.png","http://www.dubwars.com/2007/index.htm","");
                        </script>
                    </div>

I need to be updating the value of event_tout4, to count from 1-~

At the same time I need to be writing new image values in the pngpong.serverButton.. javascript..

See what i'm going for?
Thanks for any help..

 
Old July 3rd, 2007, 03:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

xsl:for-each behaves rather like a loop, but it's best to think of it as processing all the values in parallel because then you won't be misled into thinking that anything you do when processing the first element can affect the second.

For a simple counter, just use the position() function. Its value is 1 for the first item, 2 for the second, and so on.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Loop? kwilliams XSLT 1 June 16th, 2008 06:04 PM
Parsing and counting using XSLT manish_jaiswal XSLT 2 January 24th, 2008 02:38 AM
FOR LOOP IN XSLT im_himanshu2004 XSLT 0 October 10th, 2007 02:27 PM
loop in xslt vazarshahy XSLT 6 June 7th, 2006 04:46 PM
counting record numbers in a loop sniffer Classic ASP Basics 2 October 21st, 2004 11:49 AM





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