473,672 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting vertically liner xml doc to hierarchy format dynamically in any depth.

I don't even know where to begin this as hierarchy is always confusing
to construct dynamically in any form(query, xslt,etc). However it is
very easy to follow when it's presented. I've done breaking a linear
doc to 2 levels of hierarchy before, but that case had fixed level(its
depth didn't go any further than 2).

I have xml doc in attribute oriented format as following :
<Root>
<Survey ID="1" ControlType="La bel" ParentID="1" Text="1. Commute"/>
<Survey ID="2" ControlType="La bel" ParentID="1" Text="How do you
commute?"/>
<Survey ID="3" ControlType="Dr opDown" ParentID="2" Text="Car"/>
<Survey ID="4" ControlType="Dr opDown" ParentID="2" Text="Subway"/>
<Survey ID="5" ControlType="Dr opDown" ParentID="2" Text="Commuter
Rail"/>
<Survey ID="5" ControlType="Dr opDown" ParentID="2" Text="Bus"/>
<Survey ID="7" ControlType="Dr opDown" ParentID="2" Text="Walk"/>
<Survey ID="8" ControlType="La bel" ParentID="1" Text="How long is
your commute?"/>
<Survey ID="9" ControlType="Dr opDown" ParentID="8" Text="-30min"/>
<Survey ID="10" ControlType="Dr opDown" ParentID="8" Text="30min - 1
hour"/>
<Survey ID="11" ControlType="Dr opDown" ParentID="8" Text="1 hour+"/>
<Survey ID="12" ControlType="La bel" ParentID="12" Text="2. Your
company"/>
<Survey ID="13" ControlType="Te xtBox" ParentID="12" Text="Company
name"/>
<Survey ID="14" ControlType="Te xtBox" ParentID="12" Text="Employer"/>
<Survey ID="15" ControlType="Te xtBox" ParentID="15" Text="3. Other
comment"/>
</Root>

What I need to do is to format above in heirarchy form. If attribute
"ID" and "ParentID" are equal, it means that that node comes on top
level. So far, the depth of the hierarchy doesn't go any deeper than 3
levels. But I can't count on it. So ultimately what I want to have is
following :

<Root>
<Survey ID="1" ControlType="La bel" Text="1. Commute">
<Survey ID="2" ControlType="La bel" Text="How do you commute?">
<Survey ID="4" ControlType="Dr opDown" Text="Subway"/>
<Survey ID="5" ControlType="Dr opDown" Text="Commuter Rail"/>
<Survey ID="5" ControlType="Dr opDown" Text="Bus"/>
<Survey ID="7" ControlType="Dr opDown" Text="Walk"/>
</Survey>
<Survey ID="8" ControlType="La bel" Text="How long is your commute?">
<Survey ID="9" ControlType="Dr opDown" Text="-30min"/>
<Survey ID="10" ControlType="Dr opDown" Text="30min - 1 hour"/>
<Survey ID="11" ControlType="Dr opDown" Text="1 hour+"/>
</Survey>
</Survey>
<Survey ID="12" ControlType="La bel" Text="2. Your company">
<Survey ID="13" ControlType="Te xtBox" Text="Company name"/>
<Survey ID="14" ControlType="Te xtBox" Text="Employer"/>
</Survey>
<Survey ID="15" ControlType="Te xtBox" Text="3. Other comment"/>
</Root>

Has anyone does anything like this? If anyone know how to format
hierarchy in any depth, that'd be great, but I'd like know 3 levels at
least.
Thanks in advance.

Feb 14 '07 #1
8 1675
Why not just use the fact that XML is inherently tree-structured, and
let the tree hierarchy be your data hierarchy, rather than trying to
link things with IDs? MUCH easier to process for both machines and humans.

<Root>
<Survey ControlType="La bel" Text="1. Commute">
<Survey ControlType="La bel" Text="How do you
commute?">
<Survey ControlType="Dr opDown" Text="Car"/>
<Survey ControlType="Dr opDown" Text="Subway"/>
</Survey>

.... and so on.

(And actually, I'd argue that specifying that the list is a dropdown
belongs at the level of the LIST rather than on the choices. The first
step in using hierarchy is to define a hierarchy that expresses the
concepts you actually want to work with...)
Feb 14 '07 #2
On Feb 14, 11:41 am, Joseph Kesselman <keshlam-nos...@comcast. net>
wrote:
Why not just use the fact that XML is inherently tree-structured, and
let the tree hierarchy be your data hierarchy, rather than trying to
link things with IDs? MUCH easier to process for both machines and humans.

<Root>
<Survey ControlType="La bel" Text="1. Commute">
<Survey ControlType="La bel" Text="How do you
commute?">
<Survey ControlType="Dr opDown" Text="Car"/>
<Survey ControlType="Dr opDown" Text="Subway"/>
</Survey>

... and so on.

(And actually, I'd argue that specifying that the list is a dropdown
belongs at the level of the LIST rather than on the choices. The first
step in using hierarchy is to define a hierarchy that expresses the
concepts you actually want to work with...)
Unfortunately the format on the top is what I get from third party and
I do have to work with it. I have no control over "Let's use this
format, screw the one you have".

Feb 14 '07 #3
Bostonasian wrote:
Unfortunately the format on the top is what I get from third party
OK, in that case the first step may be to write a stylesheet that
restructures it along more reasonable lines. <smile/This is a
straightforward grouping problem: For each element, gather all the
elements which refer to it as their parent and move them into it as
children, processing them recursively to gather their children in turn.

Once things are in that form, other processing should be a lot more
straightforward .
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 14 '07 #4
On Feb 14, 1:13 pm, Joseph Kesselman <keshlam-nos...@comcast. net>
wrote:
Bostonasian wrote:
Unfortunately the format on the top is what I get from third party

OK, in that case the first step may be to write a stylesheet that
restructures it along more reasonable lines. <smile/This is a
straightforward grouping problem: For each element, gather all the
elements which refer to it as their parent and move them into it as
children, processing them recursively to gather their children in turn.

Once things are in that form, other processing should be a lot more
straightforward .

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Actually I have that approach already in my mind.
The reason I posted this is because I am having trouble with
explicitly manifesting detail solution(XSLT code to be exact).

Feb 14 '07 #5
On Feb 14, 6:48 pm, "Bostonasia n" <axk...@gmail.c omwrote:
On Feb 14, 11:41 am, Joseph Kesselman
<keshlam-nos...@comcast. netwrote:
Why not just use the fact that XML is inherently
tree-structured, and let the tree hierarchy be your
data hierarchy, rather than trying to link things with
IDs? MUCH easier to process for both machines and
humans.
<Root>
<Survey ControlType="La bel" Text="1. Commute">
<Survey ControlType="La bel" Text="How do you
commute?">
<Survey ControlType="Dr opDown" Text="Car"/>
<Survey ControlType="Dr opDown" Text="Subway"/>
</Survey>

Unfortunately the format on the top is what I get from
third party and I do have to work with it. I have no
control over "Let's use this format, screw the one you
have".
I would heartily recommend contacting the third party in
question and mildly suggesting to them to hire a borking
XML expert instead of saddling some DBA type with the task
of designing XML schemata.

(Oh, I just can see that: 'Hey Fred, we need to uh do urgh
some um XML stuff. Here, take this XML Expertise In Six
Productive Lunch-Breaks. One of my pointy-haired flunkies
told me it was really great.')

--
roy axenov

Feb 14 '07 #6
On Feb 14, 2:41 pm, "roy axenov" <r_axe...@mail. ruwrote:
On Feb 14, 6:48 pm, "Bostonasia n" <axk...@gmail.c omwrote:
On Feb 14, 11:41 am, Joseph Kesselman
<keshlam-nos...@comcast. netwrote:
Why not just use the fact that XML is inherently
tree-structured, and let the tree hierarchy be your
data hierarchy, rather than trying to link things with
IDs? MUCH easier to process for both machines and
humans.
<Root>
<Survey ControlType="La bel" Text="1. Commute">
<Survey ControlType="La bel" Text="How do you
commute?">
<Survey ControlType="Dr opDown" Text="Car"/>
<Survey ControlType="Dr opDown" Text="Subway"/>
</Survey>
Unfortunately the format on the top is what I get from
third party and I do have to work with it. I have no
control over "Let's use this format, screw the one you
have".

I would heartily recommend contacting the third party in
question and mildly suggesting to them to hire a borking
XML expert instead of saddling some DBA type with the task
of designing XML schemata.

(Oh, I just can see that: 'Hey Fred, we need to uh do urgh
some um XML stuff. Here, take this XML Expertise In Six
Productive Lunch-Breaks. One of my pointy-haired flunkies
told me it was really great.')

--
roy axenov
Yes I did try that. But for whatever reason, their turn around time
takes longer than me creating XSLT to transform it. Yes I know, it's
all bureaucratic BS and I am already frustrated with this even before
coding. And again, if that was all possible and have grace period time
to negotiate those issue, I wouldn't have posted this here.

Feb 14 '07 #7
Bostonasian wrote:
The reason I posted this is because I am having trouble with
explicitly manifesting detail solution(XSLT code to be exact).
Well, I gave you an algorithm, but since you're still lost I'll rephrase
it into a completely untested sketch.

<xsl:styleshe et ... and so on ... >
<xsl:template match="/">
<xsl:apply-templates select="/Root/Survey[@ID=1]"/>
</xsl:template>

<xsl:template match="Survey">
<xsl:copy>
<xsl:apply-template select="@*"/>
<xsl:apply-template select="/Root/Survey[@ParentID=curre nt()/@ID]"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|node" >
<xsl:copy>
<xsl:apply-template select="@*|node "/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

If you don't immediately understand how this works, I strongly recommend
going back and doing a few basic XSLT tutorials. This really is a
third-homework-assignment level of complexity; maybe earlier depending
on what the prereqs were.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 14 '07 #8
Bostonasian wrote:
Yes I did try that. But for whatever reason, their turn around time
takes longer than me creating XSLT to transform it. Yes I know, it's
all bureaucratic BS and I am already frustrated with this even before
coding. And again, if that was all possible and have grace period
time to negotiate those issue, I wouldn't have posted this here.
Just make sure you charge them for the time in your invoice.
If they're that stupid, they'll pay anyway because they won't
realise their error.

///Peter
Feb 15 '07 #9

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

Similar topics

0
1399
by: archway | last post by:
Hi, I would like to build a hierarchy of ProductNode objects like so ProductNode ---Product Node ---ProductNode ------ProductNode ------ProductNode ---ProductNode
3
2308
by: Chuck Reed | last post by:
I am working on a sales report where I show weekly sales by category for each of the 52 weeks in the year. Each record in my table/report has the 52 weeks of sales in it. I want to highlight to top five weeks of sales for each category by using a conditonal format to highlight these top five weeks. I've been trying to find a way to do this but have not been sucessful looking through many books on Access and in reading the user groups. If...
7
6401
by: Christopher Robin | last post by:
Hi, I'm trying to find if a function exists that would format a large (> 1000) number with comma notation on a unix type system... I currently have X = 10000; printf("X = %d\n", X); which obviously only prints:
0
1564
by: Irfan Akram | last post by:
Hello People, I would appreciate your responses on this. I am writing an asp.net web-application involving C#. I am actually building a test hierarchy at the moment, which involves producing dynamic controls, depending on user response. To be more precise, I prompt the user for the number of questions, that should be in the test. He types in a number, say 10. Then I need to ask him
4
8325
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a lot of posts regarding the htmlencode property but I do not know how to turn that off for a...
19
5204
by: Brian Kendig | last post by:
I want to have a set of nested UL elements where every LI has a checkbox associated with it, and the checkboxes are all lined up vertically either to the left or the right of the list. In other words, something like this (my apologies if you're not using a fixed- width font): x - Item 1 x - Item 1a x - Item 1b x - Item 2
9
2317
by: john coltrane | last post by:
Is there way to create a formatted string in a similar that is similar to sprintf? The same for printing, printf? C,D,E,F,G,N,X for currency, decimal, exponential, fixed, general, numerical, and hex but these do not seem to allow for specifying the number of decimals, left/right placement, or string formatting. Thanks
6
4591
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this works fine: Text='<%# Eval("Price", ApplicationContext.CurrencyFormat) %>'
5
1243
by: Berryl Hesh | last post by:
Requirements for a field that represents an EmployeeNumber: · The field is always 6 characters long, and is stored as a 'string' in the db o All characters must be digits § Regex pattern? o If the number of digits in the EmployeeNumber is less than 6
0
8498
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8418
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8940
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8840
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7457
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6249
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2830
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1831
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.