Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 10th, 2006, 06:54 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Finding the last element

Hi,
I have the problem with following xml file:

Code:
<chessgame...>
<move> <white>P d2-d4</white>   <black>N g8-f6</black></move>
<move> <white>P c2-c4</white>   <black>P g7-g6</black></move> 
<move> <white>N b1-c3</white>   <black>P d7-d5</black></move>
<move> <white>P c4-d5 x</white> <black>N f6-d5 x</black></move> 
<move> <white>P e2-e4</white>   <black>N d5-c3 x</black></move> 
<move> <white>P b2-c3 x</white> <black>B f8-g7</black></move> 
...
This xml code represent chessgame. The problem is how to find last move for particular figure (note that there is 8 Pawns and all are marked with P). I've trying to solve this problem for a days, but I didn't have to much success. Could anybody suggest me some solution for this problem?
Thanks in advance.

Reply With Quote
  #2 (permalink)  
Old March 10th, 2006, 07:43 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First improve the markup to get rid of internal syntax, e.g.

<move>
<ply player="white" piece="P" from="d2" to="d4"/>
<ply player="black".../>

Write a recursive template which walks through all the moves. Pass a parameter which contains the current position of each of the 32 pieces. Update this parameter to reflect the new position of a piece after the move. Copy the move, adding a new attribute that identifies which of the 32 pieces is being moved. (You'll have to do something special for castling, promotion, etc).

Now you've got data that's tagged with the identity of the piece making the move, it's a simple matter of (/game/move/ply)[@piece=$x][last()].

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old March 11th, 2006, 12:47 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"Pass a parameter which contains the current position of each of the 32 pieces."

How can I pass a parametar with more values? Could you give me some example, please?

Reply With Quote
  #4 (permalink)  
Old March 11th, 2006, 12:58 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can pass a nodeset as a parameter, not just single values.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old March 12th, 2006, 05:45 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You might find it useful to study the "knight's tour" example in my book. This uses most of the techniques needed to solve the problem you described.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
Finding the first child element humansky XSLT 5 April 17th, 2008 08:46 AM
finding highest value Aprile Access VBA 3 October 3rd, 2007 07:13 AM
translate element name to element name lexzeus XSLT 3 September 4th, 2006 09:04 AM
adding of element and assigning to one element sushovandatta XSLT 2 November 16th, 2004 07:04 PM



All times are GMT -4. The time now is 10:32 PM.


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