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

RE: context-independent counter

Subject: RE: context-independent counter
From: Tobias Reif <tobiasreif@xxxxxxxxx>
Date: Wed, 7 Feb 2001 08:47:25 -0800 (PST)
name counter
Wow Ben,

it works!
(in instant saxon 6.0.2)

A context-independent counter in XSLT:

[in:]

<?xml version="1.0" encoding="UTF-8"?>
<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:]

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
	<!--
	If you just want a counter, try something like this:
-->
	<xsl:template match="/">
		<svg>

		<xsl:call-template name="counter">
			<xsl:with-param name="i">1</xsl:with-param>
		</xsl:call-template>
		</svg>

	</xsl:template>
	<xsl:template name="counter">
		<xsl:param name="i"/>
		<!-- do something -->			<rect x="{$i * 10}" y="10"
width="6" height="4"/>		<xsl:if test="not($i > 10)">
			<xsl:call-template name="counter">
				<xsl:with-param name="i">
					<xsl:value-of select="$i +1"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<!--
Basically, you are recursively calling a named
template with a 
parameter;
i.e. you can do a "for i = 1 to x" loop.

Hopefully this should be enough to get you going...-->
</xsl:stylesheet>

[out:]

<?xml version="1.0" encoding="UTF-8"?>
<svg>
	<rect x="10" y="10" width="6" height="4"/>
	<rect x="20" y="10" width="6" height="4"/>
	<rect x="30" y="10" width="6" height="4"/>
	<rect x="40" y="10" width="6" height="4"/>
	<rect x="50" y="10" width="6" height="4"/>
	<rect x="60" y="10" width="6" height="4"/>
	<rect x="70" y="10" width="6" height="4"/>
	<rect x="80" y="10" width="6" height="4"/>
	<rect x="90" y="10" width="6" height="4"/>
	<rect x="100" y="10" width="6" height="4"/>
	<rect x="110" y="10" width="6" height="4"/>
</svg>

again: wow!

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.