473,785 Members | 2,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get fully qualified name of current node?

I know how to use the name() function to access the name of the
current node. How do I get the 'fully qualified' name, consisting
of the path from the root to the current node?

I.e.
<a>
<b>
<c>
</c>
</b>
</a>

When processing node c I need an xpath expression that returns
'a/b/c'. Is this available in XPath 1.0?

Jim Garrison
jh*@athensgroup .com
Oct 24 '05 #1
4 4153


Jim Garrison wrote:
I know how to use the name() function to access the name of the
current node. How do I get the 'fully qualified' name, consisting
of the path from the root to the current node?

I.e.
<a>
<b>
<c>
</c>
</b>
</a>

When processing node c I need an xpath expression that returns
'a/b/c'. Is this available in XPath 1.0?


There is nothing like "the" fully qualified name in that way, of course
there are various XPath expressions selecting a single node but there is
nothing like "the XPath" to a node.
So you need to carefully define what kind of XPath you want to have and
create that programmaticall y, for instance with an XSLT stylesheet.
For that example for instance if anything of some precision is created
it could be
/a[1]/b[1]/c[1]
your expression
a/b/c
is much to generic unless you want some optimization when there is only
one child element.
Of course
/*[1]/*[1]/*[1]
is also a fitting XPath to get at that c element.
But as said, define carefully for yourself which results you want to
have and then create an XSLT stylesheet or other program walking a tree
model to create the XPath for you. Usually you do that by looking at the
number of preceding-sibling nodes of the same name and move up to the
parent node.
Or use a tool your favourite XML editor might provide.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 24 '05 #2
Martin Honnen wrote:
Jim Garrison wrote:
I know how to use the name() function to access the name of the
current node. How do I get the 'fully qualified' name, consisting
of the path from the root to the current node?

I.e.
<a>
<b>
<c>
</c>
</b>
</a>

When processing node c I need an xpath expression that returns
'a/b/c'. Is this available in XPath 1.0?


There is nothing like "the" fully qualified name in that way, of course
there are various XPath expressions selecting a single node but there is
nothing like "the XPath" to a node.


True, but I think what he wanted was the parental location ladder back to
the root element:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<xsl:call-template name="parentage ">
<xsl:with-param name="element" select="//c"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="parentage ">
<xsl:param name="trace"/>
<xsl:param name="element"/>
<xsl:choose>
<xsl:when test="count(/|$element)=1">
<xsl:value-of select="name($e lement)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$trace"/>
</xsl:when>
<xsl:otherwis e>
<xsl:call-template name="parentage ">
<xsl:with-param name="element" select="$elemen t/parent::*"/>
<xsl:with-param name="trace">
<xsl:value-of select="name($e lement)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$trace"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

///Peter

Oct 24 '05 #3
Thanks for the response. I guess I'm surprised that XPath doesn't
provide a simple way to get the full path from the document root
without having to kludge it like this.

Or maybe I'm missing something?

Peter Flynn wrote:
Martin Honnen wrote:
True, but I think what he wanted was the parental location ladder back to
the root element:

Oct 27 '05 #4
Jim Garrison wrote:
Thanks for the response. I guess I'm surprised that XPath doesn't
provide a simple way to get the full path from the document root
without having to kludge it like this.

Or maybe I'm missing something?


No, it's just not very commonly asked for. But once written, you can
store the template in an external file and include it in any XSLT
program that needs it.

///Peter

Oct 27 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4387
by: Stefan | last post by:
I'm installing Oracle 9ias Release 2 on Windows 2000 Advanced Server. The installation instructions say to specify a fully qualified host name for the machine. What is the definition of fully qualified host name computername.domain or computername.domain.com....
0
1496
by: JMD | last post by:
I have a set of schemas for two different XML files that share common structures through the use of "import". Eventually, the main XSD file (which just gathers pieces from the common stuff to show what goes in this root element) contains: <xs:element name= "ImageBox" type="ns:ImageBox_t" form="qualified" /> I use a validating reader to pull this into an XmlDocument. Then, step
4
4032
by: Aashish Patil | last post by:
Hello, Is it possible to obtain the fully qualified name of a class in c#. What I am looking for is something analogous to Box.class.getName() that exists in Java. Its possible to get this by calling GetType() on an instance but I need to do this in a static method of the same object whose fully qualified name is needed. Thus, there is no instance available on which the GetType()
5
3020
by: fc2 | last post by:
Hi I have a problem with fully qualified names. According to the C# language specification: "Every namespace and type has a fully qualified name, which uniquely identifies the namespace or type amongst all others." However, I have problems compiling the following:
1
2325
by: Erland | last post by:
Hi all, As per my understanding in order to load an assembly using Assembly.Load() you have to provide fully qualified name of the assembly you are trying to load e.g. Assembly asmb=Assembly.Load("System.Windows.Forms,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"); In this case i will have to provide the whole big string in
0
2556
by: Rob Maui | last post by:
I use the following code in an aspx file to read the file name which I am uploading from the client PC onto the server; Dim MyFileName As String Dim MyFileColl As HttpFileCollection = Request.Files MyFileName = MyFileColl.Item(0).FileName or (alos tried) Dim PostFile As System.Web.HttpPostedFile
8
19336
by: fireball | last post by:
I wihsh to discuss whether to use fully qualified names: ..object of objects to operate (create, query..) on is good or not? If someone change order of sql code blocks in my script - this may cause lose of it's context (like: use master / use <mydb>..). I wish to have my sript independed on changes like this and always produce correct result. Does using full name make use of 'use <db>' statement unnecessary?
4
7928
by: Vivek | last post by:
Hi, Generally we work with the 2 part qualified table names in db2 i.e. <schema>. <table name> Is there a more fully qualified table name ? I've seen that a select from <database name>.<schema>.<tabnamealso works. This brings me to the next question. Is it possible to refer to a table in database 2 when connected to database 1 ? If so any privileges that are required for doing that ?
2
8209
by: patrimith | last post by:
Hi List, I am used to the following with Java: import some.package.MyClass; name = MyClass.class.getName(); The value for name will be "some.package.MyClass". For Python, I find:
0
9645
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.