Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2006, 02:46 PM
dep dep is offline
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dep
Default How to look at the previous record in a for-each

Is it possible to, while looping through a for-each, look at the previous record's value?

So that if I'm at position 2 and want to see the value of "symbol" for position 1, can this be done within the loop?

If no, how else can I accomplish this?

sorry for the noob question.


 
Old October 30th, 2006, 03:01 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

An xsl:for-each is not a loop, all nodes in the sequence are processed in parallel, in an ideal world anyway...

If you show the structure of your XML and what you need they're will most likely be a simple XPath expression to retrieve the node you want.

--

Joe (Microsoft MVP - XML)
 
Old October 30th, 2006, 03:37 PM
dep dep is offline
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dep
Default

Code:
<EZMessage action="tool.coveredcall">
  <data>
    <spread>
      <symbol>SIRF</symbol>
      <expString>Oct 06</expString>
      <expTime>1161406800000</expTime>
      <returnRate>2.637</returnRate>
      <stockPrice>22.18</stockPrice>
      <callPrice>1.10</callPrice>
      <industryName>Semiconductors</industryName>
      <spc>100.0</spc>
      <leg>
        <side>B</side>
        <securityKey>SIRF:::S</securityKey>
      </leg>
      <leg>
        <side>S</side>
        <securityKey>QIR:20061021:225000:C</securityKey>
      </leg>
    </spread>
    <spread>
      <symbol>MLS</symbol>
      <expString>Oct 06</expString>
      <expTime>1161406800000</expTime>
      <returnRate>2.157</returnRate>
      <stockPrice>15.57</stockPrice>
      <callPrice>0.95</callPrice>
      <industryName>Real Estate</industryName>
      <spc>100.0</spc>
      <leg>
        <side>B</side>
        <securityKey>MLS:::S</securityKey>
      </leg>
      <leg>
        <side>S</side>
        <securityKey>MLS:20061021:150000:C</securityKey>
      </leg>
    </spread>
    ...
  </data>
</EZMessage>
basically I want to NOT display the node if the Symbol is the same as the previous node...

 
Old October 30th, 2006, 04:10 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>I want to NOT display the node if the Symbol is the same as the previous node...


That's then a classic grouping problem, read all about it at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 30th, 2006, 04:22 PM
dep dep is offline
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dep
Default

Thank you :)

 
Old October 30th, 2006, 04:33 PM
dep dep is offline
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dep
Default

Code:
<xsl:key name="contacts-by-surname" match="contact" use="surname" />
<xsl:template match="records">
    <xsl:for-each select="contact[count(. | key('contacts-by-surname', surname)[1]) = 1]">
        <xsl:sort select="surname" />
        <xsl:value-of select="surname" />,<br />
        <xsl:for-each select="key('contacts-by-surname', surname)">
            <xsl:sort select="forename" />
            <xsl:value-of select="forename" /> (<xsl:value-of select="title" />)<br />
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>
Oye... This is enough to make a newbie's head explode.

 
Old October 30th, 2006, 04:35 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think that counts as a grouping problem, displaying data from the first occurence of each symbol. If using XSLT 1.0 then see the first post in this forum for links on grouping.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nhiberbnate Updating record using previous session dinesh_bali Intro Programming 0 February 16th, 2007 05:00 AM
Copy previous field record if next field is null ecampos Access VBA 6 June 23rd, 2006 12:55 PM
Subtracting a value from a previous value Wes Access 8 March 29th, 2006 12:17 PM
Next and Previous buttons. g_vamsi_krish ASP.NET 1.x and 2.0 Application Design 1 January 19th, 2006 11:19 AM
Record locking - user needs the next queued record cbtoolkit SQL Server 2000 0 December 6th, 2004 08:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.