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 August 8th, 2007, 07:46 PM
Registered User
Join Date: Jul 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default XPath to get next node (sibling)


i'm running .net 2.0 on winxp, and am simply trying to set a variable (using an xpath query) in an xsl sheet to the name of the previous 'month' node in an xml nodeset given a month variable (ex.: "February"). the nodeset looks like the following:

  <month name="January"></month>
  <month name="February"></month>
  <month name="March"></month>
  <month name="April"></month>



so the desired result, passing in "February" for the variable, would be "January."

i think i need to use "preceding-sibling", but i'm not exactly sure how. i've searched a fair bit on this but can't quite seem to get the syntax right. it seems that the base query to get to the given node would be something like "months/month[@name=$month]", but from there i'm fairly lost.

can anyone help?

thanks so much in advance.


Old August 8th, 2007, 07:54 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

You're almost there. Just remember that a path is a sequence of steps:


Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Old August 8th, 2007, 08:30 PM
Registered User
Join Date: Jul 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

michael, you rock! thanks so much for your reply.


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML: How to select a node with ' in it using Xpath guozai BOOK: Professional C#, 2nd and 3rd Editions 1 October 6th, 2006 12:37 PM
XPath node selection nkuar XML 1 March 4th, 2006 09:40 PM
Read xpath query from node value jaquing XSLT 2 January 11th, 2006 06:50 PM
Access Namespace Node using XPath pvasudevan XSLT 1 January 2nd, 2006 06:20 AM
Accessing values from the last sibling node graywoodhouse XSLT 3 October 29th, 2004 06:15 AM

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