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

context-independent counter

Subject: context-independent counter
From: Tobias Reif <tobiasreif@xxxxxxxxx>
Date: Wed, 7 Feb 2001 06:44:38 -0800 (PST)
li counter
Hi!

Ho to increment a variable or param with each
iteration of a for-each-loop, independent of the
context of the current node?

I need to run a for-each-loop over some elements, and
transform each to an SVG-rectangle with increasing
x-coordinate-values.

I know how to change a variable in a for-each-loop
according to for example the level of the current
node;
but now I just need a counter.

Here is how I would do it in PHP:

$line_count = 1;
while ( $line_count <= 100 )
   {
   print ("$line_count"."<br>"."\n");
   $line_count++;
   }

... and here is how I tried it in XSLT (with insatnt
saxon 6.0.2):

[in:]

<list>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
	<li>text</li>
</list>

[through:]

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:variable name="counter" select="10"/>
	<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
		<svg>
			<xsl:for-each select="/list/child::li">
				<rect x="{$counter}" y="10" width="6" height="4"/>
				<xsl:variable name="counter"
select="$counter+10"/>
			</xsl:for-each>
		</svg>
	</xsl:template>
</xsl:stylesheet>

[out:]

<svg>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
   <rect x="10" y="10" width="6" height="4"/>
</svg>

Tobi

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.