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

Hpw to know level tag position

sam
I need to know a way for knowing tag position in a xml like this:

<AAA>
<BBB>
<CCC>
<DDD_1/>
<DDD_2/>
<DDD_3/>
</CCC>
<BBB/>
</AAA>
I need to get that AAA = 1, BBB=2,CCC=3,
DDD_1=4, DDD_2=4,DDD_3=4

thanks for help.
Sam
Jul 22 '07 #1
3 2074
sam wrote:
I need to know a way for knowing tag position in a xml like this:

<AAA>
<BBB>
<CCC>
<DDD_1/>
<DDD_2/>
<DDD_3/>
</CCC>
<BBB/>
</AAA>
I need to get that AAA = 1, BBB=2,CCC=3,
DDD_1=4, DDD_2=4,DDD_3=4
count($n/ancestor::node()) where $n is your node. So with a stylesheet
you could do:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="text"/>

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

<xsl:template match="*">
<xsl:value-of select="concat(name(), ' = ',
count(./ancestor::node()))"/>
<xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 22 '07 #2
sam
Martin Honnen
count($n/ancestor::node()) where $n is your node. So with a stylesheet
Okey, but I am using XML .Net control for handling xml files.
So, how to get this value in csharp code ?

Sam

"Martin Honnen" <ma*******@yahoo.dea écrit dans le message de news:
Or**************@TK2MSFTNGP04.phx.gbl...
sam wrote:
>I need to know a way for knowing tag position in a xml like this:

<AAA>
<BBB>
<CCC>
<DDD_1/>
<DDD_2/>
<DDD_3/>
</CCC>
<BBB/>
</AAA>
I need to get that AAA = 1, BBB=2,CCC=3,
DDD_1=4, DDD_2=4,DDD_3=4

count($n/ancestor::node()) where $n is your node. So with a stylesheet you
could do:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="text"/>

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

<xsl:template match="*">
<xsl:value-of select="concat(name(), ' = ',
count(./ancestor::node()))"/>
<xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jul 22 '07 #3
sam
Martin, thank you very very very much for all samples that works fine.

Sam
Jul 23 '07 #4

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

Similar topics

72
by: The Plankmeister | last post by:
Is doing this bad: <h3>Some title or other...<a href="#pagetop">back to top</a></h3> I have a feeling it is... My problem is I'm using CSS to style the H3 into a block that spans the whole...
2
by: SRL | last post by:
Hi, This is probably a classic scenario with a shared dimension that we need to use in different cubes, where all fact tables do not offer the same level of detail. Dimension is snow-flaked. ...
3
by: Korivo | last post by:
Im getting this error while trying to read a xml file that i receive from a POST heres the code: Dim MyXmlReader As XmlTextReader Dim strNodeResult As String Dim NodeType As XmlNodeType Dim...
0
by: OMNI GROUP | last post by:
OMNI GROUP tgugger@sbcglobal.net 419-537-9447 ENTRY LEVEL/ JAVA or C/ IMMEDIATE/ IN
6
by: JohnR | last post by:
I'm running into a 'timing' or 'race' condition on my form. All textbox controls are bound to a datasource, but certain other controls (like labels) need to be updated when you move to a...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
1
by: nil111181 | last post by:
import smtplib import mimetypes; from optparse import OptionParser; from email import Encoders; from email.Message import Message; from email.MIMEBase import MIMEBase; from email.MIMEMultipart...
22
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.