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 April 20th, 2009, 10:50 AM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default Replacing xpath node with variable.

is it possible to replace a node in an xpath with a variable?

My scenario is as follows...

I have the following xpath

Code:
/Properties/Data/Result/Externals/DcrContent/PressRelease/title
However, I would like to pass the title node in to the xpath via a variable.

i.e.
Code:
<xsl:variable name="desc" select="substring-after(Description,'*')"/>
I tried this -

Code:
/Properties/Data/Result/Externals/DcrContent/PressRelease/$desc
but I'm getting the following error

mMessage[A relative location path was expected following the '/' or '//' token.]

Thanks.
 
Old April 20th, 2009, 11:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

/Properties/Data/Result/Externals/DcrContent/PressRelease/*[name()='title']

Take care if namespaces are involved.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 20th, 2009, 11:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry,

/Properties/Data/Result/Externals/DcrContent/PressRelease/*[name()=$desc]
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
rabs (April 20th, 2009)
 
Old April 20th, 2009, 11:55 AM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks. that worked.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing a table name with a server variable topshed Classic ASP Basics 3 October 4th, 2007 11:52 PM
XPath to get next node (sibling) jeft0nes XSLT 2 August 8th, 2007 08:30 PM
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
Replacing New Root Node fauster XSLT 4 October 6th, 2006 11:17 AM
XPath node selection nkuar XML 1 March 4th, 2006 09:40 PM





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