473,378 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 4113


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 programmatically, 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:stylesheet 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($element)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$trace"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="parentage">
<xsl:with-param name="element" select="$element/parent::*"/>
<xsl:with-param name="trace">
<xsl:value-of select="name($element)"/>
<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
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...
0
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...
4
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...
5
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...
1
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...
0
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 =...
8
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...
4
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...
2
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:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.