This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: context-independent counter
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] context-independent counter
- From: Tobias Reif <tobiasreif at yahoo dot com>
- Date: Wed, 7 Feb 2001 08:47:25 -0800 (PST)
- Reply-To: xsl-list at lists dot mulberrytech dot com
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