XML O/p formatting issue

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

XML O/p formatting issue

Post by shaonli »

My i/p has 3 columns.I/p is---


OWNING GROUP SECURITY-LVL GROUP-NUMBER

TIGERPRINT 4 0
TIGERPRINT1 5 1
TIGERPRINT2 6 2


Expected o/p is

<RECORDS>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT</PVAL>
</PROP>
<PROP NAME="SECURITY-LVL">
<PVAL>4</PVAL>
</PROP>
<PROP NAME="GROUP-NUMBER">
<PVAL>0</PVAL>
</PROP>
</RECORD>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT1</PVAL>
</PROP>
<PROP NAME="SECURITY-LVL">
<PVAL>5</PVAL>
</PROP>
<PROP NAME="GROUP-NUMBER">
<PVAL>1</PVAL>
</PROP>
</RECORD>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT2</PVAL>
</PROP>
<PROP NAME="SECURITY-LVL">
<PVAL>6</PVAL>
</PROP>
<PROP NAME="GROUP-NUMBER">
<PVAL>2</PVAL>
</PROP>
</RECORD>
</RECORDS>



Xpath expressions are

/RECORDS/RECORD/PROP[@NAME="OWNING-GROUP"]/PVAL/text()
/RECORDS/RECORD/PROP[@NAME="SECURITY-LVL"]/PVAL/text()
/RECORDS/RECORD/PROP[@NAME="GROUP-NUMBER"]/PVAL/text()


But o/p which I am getting is

<RECORDS>
<RECORD>
<PROP NAME="OWNING-GROUP"><PVAL>TIGERPRINT4</PVAL>0</PROP>
<PROP NAME="OWNING-GROUP"><PVAL>TIGERPRINT15</PVAL>1</PROP>
<PROP NAME="OWNING-GROUP"><PVAL>TIGERPRINT26</PVAL>2</PROP>
</RECORD>
</RECORDS>

Please check what is wrong with Xpath expressions.

Thanks
Shaonli
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...another xml document that sadly does not use the column names as the element names, so that it reflects the real meta data...... (would have been nicer if you had an element by the name of <OwningGroup>.

Simplest thing for you to do would be to first pivot the data, meaning, get each column into its own row. Then you will more easily be able to generate the repeating PROP element instances without having to resort to any custom XPath work.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

Can you please explain this more explicitly.
This is an urgent requirement.

Thanks In Advance
Shaonli
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

As has so often been explained, we at DSXchange simply don't do "urgent". If it is urgent, as you say, sign up for premium service with your support provider, and learn how expensive "urgent" is. DSXchange is a community of volunteers who post as and when they can, and then only if they have something concrete to contribute.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

Sorry Ray.....
If it is possible then please provide the solution for it.

Thanks in advance
Shaonli
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And someone will - if they can and when they can. If you truly need 'urgent' help, contact your support provider.
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Craig is right. ...and now I have a few minutes.... what you need to do is turn your 3 rows in the example above into 9 rows.... (which is what you really have in your desired XML). There are 9 "prop" elements. This type of issue usually occurs with columns that are of similar type, so for each row you need to define a pivot that will generate 3 separate rows (one for each of your pval "sets"). Get that accomplished first (search in the forum on pivot --- I'm sure there are 100's of threads on it).

Once you have nine rows, a more simplistic set of XPath will produce what you are looking for, where a column containing the "NAME" is generated with xpath that ends in @NAME, and the others are generated with simpler XPATH that ends in text(), without the explicit values in [] being needed any longer.

Again -- resolve the pivot technique first.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Look, you lucked out - Uncle Ernie back from Holiday Camp so soon. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

;) ...I can always guage people's age by which historical media "ernie" they relate me to....... (with all due respect to "The Who" there are some other classic ones).

-e
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:lol:

I'm gonna have to check out the "historical Ernie" list, it seems.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Last edited by ray.wurlod on Mon Jul 21, 2008 11:59 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

let's see... I get "Sesame Street".....Verne and Ernest (some off-beat country bumkin --- comedy or a series, not sure which)......My Three Sons (60's TV show)....Ernie Kovacs show (my parents' friends)......the move "It's a Wonderful Life"......and there are probably a few more.

:)
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

eostic wrote:Verne and Ernest (some off-beat country bumkin --- comedy or a series, not sure which)
The late Jim Varney played a character named "Ernest" and his registered trademark catch phrase was "KnoWhutImean, Vern?". Yup, spelt just like that. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

According to your suggestion I have pivoted the recors.After pivotting I am getting 9 records.
Then I am using the Xpath as
/RECORDS/RECORD/PROP/PVAL/text()

The o/p is

<RECORDS>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT
</PVAL>
</PROP>
<PROP NAME="SECURITY_LVL">
<PVAL>4
</PVAL>
</PROP>
<PROP NAME="GROUP_NUMBER">
<PVAL>0
</PVAL>
</PROP>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT1
</PVAL>
</PROP>
<PROP NAME="SECURITY_LVL">
<PVAL>5
</PVAL>
</PROP>
<PROP NAME="GROUP_NUMBER">
<PVAL>1
</PVAL>
</PROP>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT2
</PVAL>
</PROP>
<PROP NAME="SECURITY_LVL">
<PVAL>6
</PVAL>
</PROP>
<PROP NAME="GROUP_NUMBER">
<PVAL>2
</PVAL>
</PROP>
</RECORD>
</RECORDS>
But in the desried o/p is shown below.

<RECORDS>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT</PVAL>
</PROP>
<PROP NAME="SECURITY-LVL">
<PVAL>4</PVAL>
</PROP>
<PROP NAME="GROUP-NUMBER">
<PVAL>0</PVAL>
</PROP>
</RECORD>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT1</PVAL>
</PROP>
<PROP NAME="SECURITY-LVL">
<PVAL>5</PVAL>
</PROP>
<PROP NAME="GROUP-NUMBER">
<PVAL>1</PVAL>
</PROP>
</RECORD>
<RECORD>
<PROP NAME="OWNING-GROUP">
<PVAL>TIGERPRINT2</PVAL>
</PROP>
<PROP NAME="SECURITY-LVL">
<PVAL>6</PVAL>
</PROP>
<PROP NAME="GROUP-NUMBER">
<PVAL>2</PVAL>
</PROP>
</RECORD>
</RECORDS>

The i/p is

OWNING GROUP SECURITY-LVL GROUP-NUMBER

TIGERPRINT 4 0
TIGERPRINT1 5 1
TIGERPRINT2 6 2


Please sugggest.

Thanks
Shaonli
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

After pivotting the i/p I got

Input_Value,ID(which I added),Attribute
"TIGERPRINT","2","OWNING-GROUP"
"4","2","OWNING-GROUP"
"0","2","OWNING-GROUP"
"TIGERPRINT1","3","SECURITY-LVL"
"5","3","SECURITY-LVL"
"1","3","SECURITY-LVL"
"TIGERPRINT2","4","GROUP-NUMBER"
"6","4","GROUP-NUMBER"
"2","4","GROUP-NUMBER"



Now I have used the XPath


/RECORDS/RECORD/PROP/@NAME
/RECORDS/RECORD/PROP/PVAL/text()

and I got the records mentioned above.
But thing is that all 9 rows are coming under /RECORDS/RECORD/PROP structure

But each i/p record(3 i/p) comes under /RECORDS/RECORD structure.

Please suggest.

Thanks in advance
Shaonli
Post Reply