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 March 10th, 2006, 06:54 PM
Registered User
 
Join Date: Mar 2006
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.

 
Old March 10th, 2006, 07:43 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old March 11th, 2006, 12:47 PM
Registered User
 
Join Date: Mar 2006
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?

 
Old March 11th, 2006, 12:58 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old March 12th, 2006, 05:45 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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