cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to know how many child elements does a node have..??

Former Member
0 Kudos

Hi,

my source structure is like this.

>mt_root

>NODE_emp(0..n)

>name(0..n)

>id(0..n)

>city(0..n)

>NODE_company(0..n)

>name(0..n)

>location(0..n)

>reg.no(0..n)

My Requirment is like this

i would like to send the count of child elements which exists(as they are 0..n) under each node to the target field.

i.e, if i map NODE_emp, if all the elements are coming in the source payload then it should return "3"

Suggest me

Thanks inadvance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

If you use an xslt mapping, you can use the count() function

Former Member
0 Kudos

@ nicolas

in my graphical mapping is it possible with the help of UDF's..??

Former Member
0 Kudos

Hi Harini,

Have a look at this thread:

I think this is what you are looking for.

Regards,

Carlos

Former Member
0 Kudos

If you know some Java, you can create a function which loops through the child elements, and keeps a counter

Former Member
0 Kudos

@carlos

Thanks for the reply

But that case is different from my case..

Here i need the count of how many child elements are existing under my node.

In that case, They want to know how many times the node is repeating..

I think its different.

Regards

Harini

Former Member
0 Kudos

Sorry, you are right.

But I dont really undestand your mapping.

You say your source message is like:

mt_root
NODE_emp(0..n)
name(0..n)
id(0..n)
city(0..n)

Should not it be anything like...?:

mt_root

NODE_emp(0..n)

name(0..1)

id(0..1)

city(0..1)

Otherwise, How do you get 3 if the ocurrence of name, id, city is 0..unbounded?

Carlos

Former Member
0 Kudos

@carlos

Sorry for that.

my struture is exactly same as what u are thiking..

It is (child elements occurence) 0..1

Sorry for that..

Former Member
0 Kudos

Yo can do, for example, the following:

name-->mapWithDefault() -->
id-->mapWithDefault() -->             User_defined_function(a,b,c) ---> target
city-->mapWithDefault() -->

feed yor user defined function with name, id, city after putting mapwithDefault in every node.

Within your function, check if your parameters are empty and count it.

Return the count. Obviously the result should be either 0 or 1 or 2 or 3.

Carlos

Edited by: Carlos Gonzalez on Dec 3, 2008 5:37 PM

Former Member
0 Kudos

@ carlos

Once again Thanks for u r concern..

It will help me in the present situation..

Can we write a generic UDF which will help us permanently..?

i mean in present scenario i will pass my three child elements but if the structure is too big then it will not be suitable right..??

Regards,

Harini.G

SudhirT
Active Contributor
0 Kudos

Hi Harini,

try this logic.

take all the source fields, and then use count function for each field and then the add function for two fields and then again add function for output of first add function with the third field and pass to target node.

thanks.

Former Member
0 Kudos

Hi harini

You can do like this

http://www.flickr.com/photos/32274480@N06/3081436182/

Thanks

Gaurav

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi harini,

Do the mapping like below.

Source field----Remove contextcount---target feild

Regards,

Leela