473,396 Members | 1,927 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,396 software developers and data experts.

Level information for XML

HI Gurus,

I have xml file in this format

<hierarchy>
<entity>
<contents>
<entity>
</entity>
</contents>
</entity>
<entity>
<contents>
<entity>
</entity>
</contents>
</entity>
</hierarchy>

I want to have attribute level for all <entity> node
like

<entity level=1>
<contents>
<entity level=2>
</entity>
</contents>
</entity>
<entity level=1>
<contents>
<entity level=2>
</entity>
</contents>
</entity>

Can someone help to get this using xslt.

thanks
gbk

Jul 20 '05 #1
1 1461
> HI Gurus,

I have xml file in this format

<hierarchy>
<entity>
<contents>
<entity>
</entity>
</contents>
</entity>
<entity>
<contents>
<entity>
</entity>
</contents>
</entity>
</hierarchy>

I want to have attribute level for all <entity> node

Can someone help to get this using xslt.

Coming right up:-)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output indent="yes" method="xml"/>

<xsl:template match="hierarchy">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="entity">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="level"><xsl:value-of select="count(ancestor::entity) +1 "/></xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="contents">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

P.S. remember that attributes have to be qouted at all times in XML.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2

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

Similar topics

2
by: robert | last post by:
well, talk about timely. i'm tasked to implement a security feature, and would rather do so in the database than the application code. the application is generally Oracle, but sometimes DB2. ...
9
by: yu_sha | last post by:
Hello everyone We have a bunch of components registered under COM+ with 'transaction required' option. On the client we are using iSeries Access 5.2.0, with all possible fixes applied...
3
by: Ais | last post by:
Hi.. Presently i'm trying to install IBM Db2 Software on my Windows XP Operating systems. I'm using IBM(R) DB2(R) Universal Database Enterprise Server Edition, Version 8.1. After...
4
by: Mike MacSween | last post by:
It's a form, with (so far) 4 tab pages on it, each of which holds 2/3/4 subforms. (I like tabbed forms by the way - do we all?) Basically the subforms are different ways of looking at the...
3
by: Eric Porter | last post by:
Dear All, I have a VB6.COM program using a VB6.COM DLL, which in turn uses ADODB that performs various bits of SQL. I have re-written the VB6.COM DLL in C#.NET (with a VB6 shell), which uses...
1
by: riceboy_inc | last post by:
Hello; First time posting and hoping to get some help! I have been going to school for Computer Science for 2+ years now, and am finally getting into some serious courses. I recently had to work...
1
by: Friends | last post by:
Hi I need to set security for row level but not based on Database user's login. It should be based on the user table login. For the particular user I need to allow only the particular records to...
7
by: pamela fluente | last post by:
I have been using something like: public void SaveJPG(Image Image, string FileName, long QualityLevel_0_100, long ColorDepthLevel) { ImageCodecInfo ImageCodecInfoJPG =...
6
by: python | last post by:
I need to generate multi-level incrementing labels for an outline/hierarchy where the string for each level of a label is based on an incrementing sequence like 1, 2, 3 or A, B, C, or even I, II,...
7
by: db2admin | last post by:
hello, where can i see what optimization level a certain sql has used ? is there any snapshot, event monitor, query patroller information which can be used to see that ? regards, db2admin
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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,...

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.