Get value of Node Name
This is an open discussion with 4 replies, filed under XSLT.
Search
Try passing an XPath expression to the name function directly:
local-name(//*[@handle=$page])
Remember it is a function, so takes an argument inside the parenthesis. If this omitted (as per your example) then the current context node is assumed.
You could also try caching the first query to a variable, then calling name() or local-name() on that variable.
Unless you're dealing with XML namespaces, you can just use name()
. local-name()
is there to access the current namespace only, so you probably don't need it with normal Symphony XML.
Thanks Nick - that did the trick!
@timchesney: you should try to stay away from //
selectors. It is best to write out the entire path of the nodes you wish to select for performance reasons and to prevent unwanted results!
Hey Remie,
Yeah - I generally do steer clear of them. In this case I only have the handle attribute of an unknown element so I'm basically searching the whole tree. I could narrow it down to data/datasource/entry/
I guess but there is only one datasource for the page and one entry so I doubt there would be much of a performance improvement.
I'm only doing it in this silly way because I set the whole thing up in a dumb way ages ago and I'm trying to hack in some new functionality. Not ideal!
Create an account or sign in to comment.
Hi there,
I would like to get the value of a node name.
name()
andlocal-name()
don't seem to work - else I am using them wrong.My XML
All I have is the value of one of the handles from URL params
$page
(so one of nice-page, another-page, sexy-page or any other page).I need to get which page number I have so I can use that to find other nodes from that page (all of which are at the same level in the XML tree because some muppet (me!) made this for a client and they now want to change how it works but keep existing data).
I can use
To get the value of the node but I really want to get the name of the node. Something like:
So if
$page = nice-page
I could get displaypage-1-name
Then I can use a string function to just get the page number eg "page-1" which I can use to match other nodes.
Any ideas - hopefully I'm just using
local-name()
wrong but I've tried a lot of combinations!Cheers.