RE: [xsl] number continuation problem

Subject: RE: [xsl] number continuation problem
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Fri, 27 Jun 2003 09:30:34 +0100

>  the second self::else should of course be an self::if (although it
>  produces the same result on your test case)
> 
> and (either) one of the &gt; should be &gt;= otherwise if both branches
> have the same number of nodes you'll skip over both of them.
> 
> David

Hi David,

Thanks for the great example, I've added the changes you mentioned.  There's one problem in that <else>'s shouldn’t count it's preceeding <if>'s nodes (they should both start with the same number).  Using the example below, you should see that the 3rd from last entry gets reported as a 7 when it should be 5.  

<root>
	<if>
		<node>(1)</node>
		<node>(2)</node>
	</if>
	<else>
		<node>(1)</node>
		<node>(2)</node>
		<node>(3)</node>
	</else>
	<if>
		<node>(4)</node>
	</if>
	<else>
		<node>(4)</node>
	</else>
	<if>
		<node>(5)</node>
		<node>(6)</node>
	</if>
	<else>
		<node>(5)</node>
	</else>
	<if>
		<node>(7)</node>
	</if>
	<else>
		<node>(7)</node>
	</else>
</root>

Now, if you make it handle nested if/else's within nodes that would be special :)


Heres the template with the modifications you've stated (apologies for not pretty printing it):

<xsl:template match="node">
.<xsl:value-of select="
1 +
count(preceding-sibling::node) +
count(../preceding-sibling::if[count(node)&gt;count(following-sibling::*[1][self::else]/node)]/node) +
count(../preceding-sibling::else[count(node)&gt;=count(preceding-sibling::*[1][self::if]/node)]/node)
"/>.<xsl:value-of select="."/>
</xsl:template>


cheers
andrew


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
 

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


Current Thread