This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

context-independent 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]