[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

preceding...please help understanding...

Subject: preceding...please help understanding...
From: "Bill Carter" <bcarter2003@xxxxxxxxxxx>
Date: Sat, 07 Sep 2002 12:34:22 -0500
cbs ticker
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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.