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 July 21st, 2005, 10:12 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to clayman58
Default finding the most recent node...

I need to be able to locate a previous node and its attributes from my current location. More specifically, I need to locate the most current node from my current position.

For example, I need to find the most current node named "THISNODE"
I tried (ancestor::THISNODE)[last()].

This seems not to give me what I want.
I need your help please.

I thank you in advance.
Clayton

 
Old July 21st, 2005, 12:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's hard to give you the correct code, since I don't know what you mean by "a previous node" or "the most current node". Perhaps you could give an example.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 21st, 2005, 12:39 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to clayman58
Default

Let try this...
SAMPLE CODE:

<subparagraph>

<subparagraph>
... (some more random node that are unimportant in this situation

<continuation style="subparagraph">

OK. When I reach the continuation node, I read the style attribute. In this case, it is subparagraph. When I see that I have to be able to read the first preceding "subparagraph" to specific style information. I put a comment right next to the <subparagraph> that I need.

Sorry about the verbage in the initial note, I believe that is clearer.
I thought that (ancestor::subparagraph)[last()] would do the trick but to no avail it seems.
Thanks for your help




 
Old July 21st, 2005, 01:14 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The "random" nodes are not unimportant, they significantly affect the answer.

Trouble is, you're using terminology imprecisely. When you say "preceding", I suspect you are not using the word in the sense of the XPath preceding axis. You are also using "node" when referring to source XML rather than to the tree model.

The expression

(ancestor::subparagraph)[last()]

finds the innermost enclosing subparagraph element of the context node. This looks like the right thing from what I can see, but the information you've given is very incomplete.

There could be other things wrong: you might be at the wrong context node, there might be namespaces in force, ...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 21st, 2005, 01:31 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to clayman58
Default

Explain to me context node. How does it differ from the current node?
Maybe this is where I am running into trouble. I just want to be able to reverse parse the tree from my current position and find the first tag(<subparagraph>)

Shouldn't this do it: "(ancestor::subparagraph)[last()]"
I think you understand what I am trying to accomplish. Forgive me for being so incoherent. I have been working on this and I am at my wits end:)
Thanks for you help.

 
Old July 21st, 2005, 01:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT 1.0 uses the term current node, XPath 1.0 has a context node. You're in XPath, so it's the context node that matters. Usually they are the same, however.

I think it would be useful if you showed a complete cut-down source document and a complete cut-down stylesheet that demonstrate what you are trying to do and what result you are actually getting. This will help me to identify your error - which is quite likely to be in part of the code that you left out because you didn't realize it was relevant.

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
finding if a node value doesn't exist mphare XSLT 3 August 19th, 2007 05:42 PM
Finding parent node Chamkaur XSLT 4 August 9th, 2006 06:26 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM
Problem regarding finding the node in xslt. rohitjain13 XSLT 1 October 6th, 2005 03:26 AM





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