473,399 Members | 2,478 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,399 software developers and data experts.

[XSLT] How to obtain nesting level?

Hi,

I have several nested layers of <node> element that are processed by an XSLT
template. Is there any possibility to determine the depth of a node in the
overall nesting hierarchy? For example, I would like to obtain 0 for the
root <node> tag; 1 for all child <node> tags; 2 for all tags that are child
<node> tags of all previous <node> tags (those of level 1); and so on.

Is there any way to do this?
Many thanks,
Phil
Nov 12 '05 #1
3 3139
Philipp Schumann wrote:
I have several nested layers of <node> element that are processed by an XSLT
template. Is there any possibility to determine the depth of a node in the
overall nesting hierarchy? For example, I would like to obtain 0 for the
root <node> tag; 1 for all child <node> tags; 2 for all tags that are child
<node> tags of all previous <node> tags (those of level 1); and so on.

Is there any way to do this?


1. Simple one - count(ancestor::*)
2. Powerful one - xsl:number instruction.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2


Philipp Schumann wrote:

I have several nested layers of <node> element that are processed by an XSLT
template. Is there any possibility to determine the depth of a node in the
overall nesting hierarchy? For example, I would like to obtain 0 for the
root <node> tag; 1 for all child <node> tags; 2 for all tags that are child
<node> tags of all previous <node> tags (those of level 1); and so on.


XSLT makes use of XPath and XPath knows several axes. One of them is the
ancestor axis so you could for instance count the number of elements on
the ancestor axis
count(ancestor::*)

There is also the instruction xsl:number which might do what you need.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3
Martin & Oleg,

thanks!

"Philipp Schumann" <ph**@mokka.org> schrieb im Newsbeitrag
news:OO**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have several nested layers of <node> element that are processed by an
XSLT template. Is there any possibility to determine the depth of a node
in the overall nesting hierarchy? For example, I would like to obtain 0
for the root <node> tag; 1 for all child <node> tags; 2 for all tags that
are child <node> tags of all previous <node> tags (those of level 1); and
so on.

Is there any way to do this?
Many thanks,
Phil

Nov 12 '05 #4

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

Similar topics

6
by: Mikko Nummelin | last post by:
As the XSLT namespace is declared to be used in XSL documents like this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> , isn't this a risky practice as it...
9
by: Iain | last post by:
I want to create an XML configuration file which might look like <REGION Name="Europe" WingDing="Blue"> <COUNTRY Name="UK" WingDing="white"> <TOWN Name="London" WingDing="Orange" /> </COUNTRY>...
3
by: shaun roe | last post by:
I have a document about 4 levels deep and in my XSLT I want to generate a unique string ID for each basic element based on its path through the hierarchy. If I use recursion, I am continually...
3
by: Alex | last post by:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net framework XSLT processor. The intent was to just copy the entities...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
4
by: Iain | last post by:
Hi all, I am try to split the some data out of a nested xml file and get all the data in one new xml file. I have two XSLT files one takes the personal information and one takes the data out of...
4
by: kl.vanw | last post by:
I would like to count the nesting level in template classes. How can I make the following work? #include <assert.h> template <class T> class A { public: A() { // what goes here?
4
by: dwergkees | last post by:
Hi, Got a litte problem here. I'm trying to create a XSLT file that will do a transformation from WordML format (MS Word XML format, see...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
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,...
0
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...

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.