473,399 Members | 2,858 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.

Parsing node names

Hello,

I don't have sufficient experience with XSLT, and would really
appreciate somebody's help in me giving ideas on solving a problem I
have. Let's consider the following XML file:

<RootNode>
<RootNode:SubNode1>
<RootNode:SubNode1:SubNode1>...</RootNode:SubNode1:SunNode1>
</RootNode:SubNode1>
<RootNode:SubNode2>
<RootNode:SubNode2:SubNode1>...</RootNode:SubNode1:SunNode1>
<RootNode:SubNode2:SubNode2>...</RootNode:SubNode1:SunNode2>
</RootNode:SubNode2>
. . .
</RootNode>

This file has only 2 known features:
1. The name of the root node is RootNode
2. We DON'T KNOW the names of the children nodes in advance. We do
know, however, that they are formed by combining the name of the parent
with the name of the child; colon is used as a separator.

I need to format the data and to get rid of long node names (leaving
only the last part of the name):

RootNode
SubNode1
SubNode1 -> Node's data
SubNode2
SubNode1 -> Node's data
SubNode1 -> Node's data

Since the nodes names are not known in advance, I assume there is no a
straighforward way of using XSLT templates for processing. I would
appreciate your ideas.

Thanks a lot!

Alex.

Jul 20 '05 #1
1 1517
"Alex" <as******@hotmail.com> writes:
Hello,

I don't have sufficient experience with XSLT, and would really
appreciate somebody's help in me giving ideas on solving a problem I
have. Let's consider the following XML file:

<RootNode> Note the root node in Xpath is / representing the document of the
whole document it is the parent of the top level element, and never has
a name.
<RootNode:SubNode1>
<RootNode:SubNode1:SubNode1>...</RootNode:SubNode1:SunNode1>
</RootNode:SubNode1>
<RootNode:SubNode2>
<RootNode:SubNode2:SubNode1>...</RootNode:SubNode1:SunNode1>
<RootNode:SubNode2:SubNode2>...</RootNode:SubNode1:SunNode2>
</RootNode:SubNode2>
. . .
</RootNode>

This file has only 2 known features:
1. The name of the root node is RootNode
2. We DON'T KNOW the names of the children nodes in advance. We do
know, however, that they are formed by combining the name of the parent
with the name of the child; colon is used as a separator.
If the colon is used without declaring namespaces for the prefix then
the input does not conform to the xml namespaces specification (and
contravenes a strong hint in the core xml spec that you should not do
that) as such the file may not be used with Xpath/xslt/XML-schema
or any other Namespace aware XML tool.

If you ran some text transform such as
sed -e "s/:/_/g"
to change all : to _ so that you could parse the input with a namespace
aware parser, then you could use xslt to do the transform that you
require in a fairly straight forward way, you'd just need someththing
like
<xsl:template match="*">
<xsl:element name="substring-after(name(),concat(name(..),'_'))">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>


I need to format the data and to get rid of long node names (leaving
only the last part of the name):

RootNode
SubNode1
SubNode1 -> Node's data
SubNode2
SubNode1 -> Node's data
SubNode1 -> Node's data

Since the nodes names are not known in advance, I assume there is no a
straighforward way of using XSLT templates for processing. I would
appreciate your ideas.

Thanks a lot!

Alex.

David
Jul 20 '05 #2

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

Similar topics

0
by: Yang Xiao | last post by:
Hi all, I'm having some problems with parsing XML with DOMParser. What I want is to filter out particular elements in the XML, the sample XML looks like this. Thanks in advance. Yang ...
2
by: littlefitzer | last post by:
Hi, I have come across a tricky little problem, I hope maybe one of you can help. The problem I am having is that I need to parse two seperate values from an XML document using XSL. The two...
1
by: Don Tucker | last post by:
Hello, I am developing in Visual Studio .NET 2005. I am attempting to parse an XML string by using the example given in the help files: ...
5
by: kotori | last post by:
hi, i have the following XML data file: <?xml version="1.0" encoding="utf-8"?> <!--This is a creature file generated by Kotori's C# code--> <!--This file will contain every enemies stats in the...
3
by: Daniel Nogradi | last post by:
Hi list, I have an awk program that parses a text file which I would like to rewrite in python. The text file has multi-line records separated by empty lines and each single-line field has two...
0
by: Divya Prakash | last post by:
Hi But I am unable to parse all the nodes of the tree .....especially the subtree of the main tree It displays only the sibling not the subtree Regards Divya
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
0
by: gnewsgroup | last post by:
I need to bind *some* nodes of an xml document to an asp.net Menu control. The problem is that the XML document uses the same node name and attribute name for for the entire document among all...
6
by: Paul Wilson | last post by:
Hi all, I'd like to be able to do the following to a python source file programmatically: * Read in a source file * Add/Remove/Edit Classes, methods, functions * Add/Remove/Edit Decorators *...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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
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.