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 November 6th, 2004, 01:29 PM
Authorized User
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parameter value as node path, doesn't work

Hi,

I'm trying to reach a text in my XML file using an XSLT which contains a parameter (I enter its value externally using Javascript, I tested it works). Problem is when I write an X-Path containing value of that paramter such as:

../$language/FullName

it doesn't give any output. I also tried :

../{$language}/FullName and ../'{$language}'/FullName
still no luck. I even tried this:
<xsl:variable name="fullnamepath">
<xsl:value-of select="node(concat('../',$language,'/FullName'))"/>
</xsl:variable>
just one line above my X-path call, this gives output as text as expected, I couldn't find a way to change it to xpath.
Nothing works. When I explicitly enter the xpath such:

../English/FullName
it works (as expected).

I'd really apreciate if you can tell me a way to overcome this problem. I want to use value of my language parameter in a xpath.
 
Old November 6th, 2004, 01:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Variables in XSLT represent values, not parts of expressions. It's not a macro language that works by textual substitution. If the value of $p is the string "english", then ./$p/code means ./"english"/code. You can't have a string literal in the middle of a path expression, and therefore you can't have a string-valued variable there either. In fact, it's worth remembering that there is no way in XSLT of constructing XPath expressions dynamically at run-time.

But if $p is a string, it should give you an error, not "no output".

Also, a leading "./" is always redundant.

Probably the expression you are looking for is

*[name() = $p]/code

Michael Kay
http://www.saxonica.com/
 
Old November 6th, 2004, 02:15 PM
Authorized User
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yep that's it, I just found it and came here to post my solution:

../*[name(.)=$language]/FullName

Thanks to you I now see that I don't even need to put that dot in parantheses.

The reason I said I don't get any output instead of saying 'I get error', is because I didn't get any error messages. That's maybe because my XML and XSL are parsed in a javascript code, and that the part in xsl giving error does not affect execution of the rest, maybe.

Note: Does it sound funny if I say "no output"? Shall I say 'doesn't return anything'. I'm no native english speaker.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with path for loading Pics (app.path) Tabbasum Beginning VB 6 2 November 15th, 2007 04:57 AM
Retrieve numbered node path from xml jeft0nes XSLT 6 July 20th, 2007 03:59 PM
Implementing the all-path shortest path problem bitwords XSLT 1 December 6th, 2006 11:37 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





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