473,544 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find Xpath Expn of current node using ancestor-or-self

9 New Member
I'm trying to Xpath EXprn for a current node(name unknown).I tried using the below syntax,but it fails .Pls help.

<xsl:variable name= "xpath" select ="name(ances tor-or-self::(.))"/>
Oct 5 '07 #1
4 3444
2,057 Recognized Expert Top Contributor
<xsl:variable name="xpath" select="name()"/>
<xsl:variable name="xpath" select="local-name()"/>
Oct 5 '07 #2
9 New Member
nmae() or local-name() would only return me th ename of the current node.But i'm trying to find out the Xpath Expression ,which would return the ancestors names also

I need the name of current node plus its ancestors.

ex: root/toplevelnode1/node2/ current node

So i tried :

<xsl:variable name= "xpath" select ="name(ances tor-or-self::[name()])"/>

I need the syntax which would return current nodes path from the root.Pls help.

thanks in advance.
Oct 5 '07 #3
2,057 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name= "xpath">
  2.   <xsl:for-each select="ancestor::*">
  3.     <xsl:value-of select="name()"/><xsl:text>/</xsl:text>
  4.   </xsl:for-each>
  5.   <xsl:value-of select="name()"/>
  6. </xsl:variable>
Oct 5 '07 #4
9 New Member
Cool!! That worked Thanks!!
Oct 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Jon Thackray | last post by:
I'm trying to use XPath to enable me to number items within sections in a paper. I have so far tried about ten things, all of which it seemed to me should work, and none of which do. Essentially what I want is a count of the number of sections preceding the section which is (the unique section) ancestor of the current node. Functionally this...
by: Colin Fox | last post by:
Hi, all. Within an xsl template, you can use the <xsl:attribute> tag to set an attribute of the current output node. This is great. However, I need to be able to set an attribute of an ancestor node. Here's the relevant part of my xsl: <xsl:template match="myform:field" mode="single">
by: Raed Sawalha | last post by:
I have following XML: How can I find the depth of XML? in other word max level of the XML <Root> ----- level 0 <Name>----- level 1 <FirstName>name</FirstName> ---- level 2 <LasName>lname</LastName> <MiddleName>mName<MiddleName> </Name>
by: David Thielen | last post by:
XPathNavigator nav = MyCreateNav(); // InnerXml == "software" nav.SelectSingleNode"."); The select returns an exception: + $exception {"'.' has an invalid token."} System.Exception {System.Xml.XPath.XPathException} Any idea why? --
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
by: orit | last post by:
I have the following xml: <?xml version="1.0" ?> <course> <globalProperties> <externalMetadata> <source>ADL</source> <model>ADL SCORM 1.0</model> </externalMetadata> </globalProperties>
by: werD | last post by:
Hello, Im wondering about using xml to store relational data. It works well with .net but im having some trouble with the xsl/xpath. Lets say that I have an xml like <data> <files> <file categoryid="1" name-"a file"/>
by: provowallis | last post by:
Hi all, I've been struggling with this for a while so I'm hoping that someone could point me in the right direction. Here's my problem: I'm trying to get the XPath for a given node in my document and then store that XPath as an attribute of the element itself. If anyone has a recommendation I'd be happy to hear it. Thanks,
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
by: bruce | last post by:
hi... i can use an xpath query to create a node from an html/dom representation. however, if i have a node, is there a way to generate an xpath query from the node. in testing with firefox/dom inspector, i can use "ancestor::*", but i can't determine where/how to implement this using mechanize/libxml2dom thanks
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.