Hi,
I am having trouble understanding preceding.
My simple xml:
<stocks>
<ticker>AAA</ticker>
<ticker>ABT</ticker>
<ticker>BIG</ticker>
<ticker>CBS</ticker>
<ticker>CBS</ticker>
<ticker>IBM</ticker>
<ticker>XYZ</ticker>
</stocks>
I want to display an html table with all the tickers in rows except for
ones that are the same as the previous one (in this case CBS repeats)
here is my xsl snippet to try to accomplish this:
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<xsl:for-each select="stocks/ticker">
<xsl:if test=". != preceding::ticker">
<tr>
<td><xsl:value-of select="." />: Pos:<xsl:value-of select="position()"
/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
Here is what I wanted:
AAA: Pos:1
ABT: Pos:2
BIG: Pos:3
CBS: Pos:4
IBM: Pos:6
XYZ: Pos:7
Here is what I got (what happend to AAA and why is CBS: Position 5
showing?):
ABT: Pos:2
BIG: Pos:3
CBS: Pos:4
CBS: Pos:5
IBM: Pos:6
XYZ: Pos:7
not right... So now I try to change the if line to:
<xsl:if test=". = preceding::ticker">
so what I think I am saying is that if the ticker is the same as the
preceding one show it's name but no others.
here is my xsl snippet now (I am displaying the position now):
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<xsl:for-each select="stocks/ticker">
<xsl:if test=". = preceding::ticker">
<tr>
<td><xsl:value-of select="." />: Pos:<xsl:value-of select="position()"
/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
Here is my output:
CBS: Pos:5
exactly what I expected. the fifth ticker is CBS and it is the same as the
forth ticker (CBS), so it shows it.
Why doesn't the previous one work as expected. What am I missing here about
preceding?
thanks,
will
_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list