Topic: [XSL] incrementing a variable in a for-each (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=10910" title="Pages that link to Topic: [XSL] incrementing a variable in a for-each (Page 1 of 1)" rel="nofollow" >Topic: [XSL] incrementing a variable in a for-each <span class="small">(Page 1 of 1)</span>\

 
poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 02-17-2003 17:08

Hello there,

I have to split an XML in two parts and exclude some entries according to an attribute. The first part must feature the first six visible entries.

code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1"/>

<xsl:template match="root">

<xsl:variable name="entriesVisible" select="0" />
<xsl:variable name="entriesDone" select="0" />

<table border="1">
<tr><xsl:for-each select="entry">
<td>
entriesVisible = <xsl:value-of select="$entriesVisible" /><br />
entriesDone = <xsl:value-of select="$entriesDone" /><br />
<xsl:if test="$entriesVisible < 6">
<xsl:if test="@tem_id != 6 and @tem_id != 7">

<xsl:variable name="entriesVisible" select="1+$entriesVisible" /> <!-- should be increased -->

<xsl:call-template name="1stPassEntries" />

</xsl:if>
</xsl:if>
<xsl:variable name="entriesDone" select="$entriesDone + 1" /> <!-- should be increased -->
</td></xsl:for-each>
</tr>
</table>

<hr /><!-- separator -->

<table border="1">
<tr><xsl:for-each select="entry">
<td>
entriesVisible = <xsl:value-of select="$entriesVisible" /><br />
entriesDone = <xsl:value-of select="$entriesDone" /><br />
<xsl:if test="position() > $entriesVisible">
<xsl:if test="@tem_id != 6 and @tem_id != 7">

<xsl:variable name="entriesVisible" select="1+$entriesVisible" /> <!-- should be increased -->

<xsl:call-template name="1stPassEntries" />

</xsl:if>
</xsl:if>
<xsl:variable name="entriesDone" select="$entriesDone + 1" /> <!-- should be increased -->
</td></xsl:for-each>
</tr>
</table>

</xsl:template>

<xsl:template name="1stPassEntries">
<b><xsl:value-of select="@name" /></b>
</xsl:template>

</xsl:stylesheet>


sorry for the length of that XSL.

With the code above, the variables entriesVisible and entriesDone are stuck at zero. And when I put the first declaration of theses variables right below the <xsl:template match="root">, SABLOTRON screams Warning: Sablotron error on line 1976: conflicting variable bindings 'entriesVisible' >__<


Thanks in advance.

Mathieu "POÏ" HENRI

[This message has been edited by poi (edited 02-17-2003).]

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 02-18-2003 21:27

Perhaps this might help http://www.biglist.com/lists/xsl-list/archives/200210/msg01105.html

There are several different tips on this but they all seem to center on the fact that
you can't change the value of a variable once it's bound.


I'm not that good on XSL, but can't you use <xsl:value-of select="count(YOUR_SELECT_HERE)"/> and compare that to a value?
/Dan

<edit>Hold it, just found this http://www.javertising.com/webtech/codesamples/recursion.asp It seems to do more or less exactly what you need (providing I understood your templates correctly...) It's a recursive template. </edit>

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

[This message has been edited by DmS (edited 02-18-2003).]



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu