Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parent-Child Unbound Transformation from Linear Structure

vv338251huMay 22 2013 — edited May 23 2013
Hi ,

We need to convert the linear people structure into Parent-Child relation with unbounded depth using XQuery. To give in detail, we have the XML schema as

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/ParentChild" xmlns:tns="http://www.example.org/ParentChild" elementFormDefault="qualified">

<complexType name="People">
<sequence>
<element name="id" type="string" />
<element name="name" type="string" />
<element name="age" type="string" />
<element name="parentId" type="string" minOccurs="0" />
</sequence>
</complexType>

<complexType name="Peoples">
<sequence>
<element name="people" type="tns:People" maxOccurs="unbounded"></element>
</sequence>
</complexType>
<element name="Peoples" type="tns:Peoples"></element>
<element name="People" type="tns:People"></element>

<complexType name="Parent">
<sequence>
<element name="id" type="string" />
<element name="name" type="string" />
<element name="age" type="string" />
<element name="child" type="tns:Parent" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>

<complexType name="Parents">
<sequence>
<element name="Parent" type="tns:Parent" maxOccurs="unbounded" ></element>
</sequence>
</complexType>

<element name="Parents" type="tns:Parents"></element>
<element name="Parent" type="tns:Parent"></element>

</schema>

The input structure can appear as
<?xml version="1.0"?>
<ns0:Peoples xmlns:ns0="http://www.example.org/ParentChild">
<ns0:people>
<ns0:id>1</ns0:id>
<ns0:name>x</ns0:name>
<ns0:age>11</ns0:age>
<ns0:parentId>2</ns0:parentId>
</ns0:people>
<ns0:people>
<ns0:id>2</ns0:id>
<ns0:name>y</ns0:name>
<ns0:age>11</ns0:age>
<ns0:parentId>3</ns0:parentId>
</ns0:people>
<ns0:people>
<ns0:id>3</ns0:id>
<ns0:name>z</ns0:name>
<ns0:age>11</ns0:age>
</ns0:people>
<ns0:people>
<ns0:id>5</ns0:id>
<ns0:name>a</ns0:name>
<ns0:age>11</ns0:age>
</ns0:people>
</ns0:Peoples>

The response should be like below
<?xml version="1.0"?>
<ns0:Parents xmlns:ns0="http://www.example.org/ParentChild">
<ns0:Parent>
<ns0:id>3</ns0:id>
<ns0:name>z</ns0:name>
<ns0:age>11</ns0:age>
<ns0:child>
<ns0:id>2</ns0:id>
<ns0:name>y</ns0:name>
<ns0:age>11</ns0:age>
<ns0:child>
<ns0:id>1</ns0:id>
<ns0:name>x</ns0:name>
<ns0:age>11</ns0:age>
</ns0:child>
</ns0:child>
</ns0:Parent>
<ns0:Parent>
<ns0:id>5</ns0:id>
<ns0:name>a</ns0:name>
<ns0:age>11</ns0:age>
</ns0:Parent>
</ns0:Parents>

We tried with below XQuery, but it is not resulting as expected.

(:: pragma bea:global-element-parameter parameter="$peoples" element="ns0:Peoples" location="ParentChild.xsd" ::)
(:: pragma bea:global-element-return element="ns0:Parents" location="ParentChild.xsd" ::)

declare namespace ns0 = "http://www.example.org/ParentChild";
declare namespace xf = "http://tempuri.org/RecursiveParentChild/ParentChild/";

declare function xf:ParentChild($peoples as element(ns0:Peoples))
as element(ns0:Parents) {
<ns0:Parents>
{
let $results := <a>{
for $people1 in $peoples/ns0:people where (not (exists ($people1/*:parentId)))
return
<ns0:Parent>
<ns0:id>{ data($people1/ns0:id) }</ns0:id>
<ns0:name>{ data($people1/ns0:name) }</ns0:name>
<ns0:age>{ data($people1/ns0:age) }</ns0:age>
</ns0:Parent>
}
</a>

let $result1 :=
for $people1 in $peoples/ns0:people where (exists ($people1/*:parentId))
return
if (data($people1/ns0:parentId) = data($results/ns0:id)) then
<ns0:child>
$people1/*
</ns0:child>
else()

return $result1
}
</ns0:Parents>
};

declare variable $peoples as element(ns0:Peoples) external;

xf:ParentChild($peoples)

Anyone tried similar kind of XQuery?. THere is a possibility that the child node can appear before the parent node, how we can handle that as well?

Any help on this is appreciated

Regards
Venkata Madhu

Comments

kdario

Hmm, it seems that this forum has some issues(or 'features')

Post above is reply to this thread: Image field cannot refresh when navigate records in jsf page so I don't know how this became totally new thread

Dario

BAO.SZ

Dario,

As you said, this topic is off the original thread (Image field cannot refresh when navigate records in jsf page), but is valuable to me. so I branch it as a new one.

I have two furthur question2:

1.Your suggestion to refresh page data seems a bit complicated, does it the best practice for the job?

--It seems, we also need to use Active Data technology?

2.Can have more evidence or reference docs on this sayings:

"normal way" to refresh page is usually very bad for applications based on JSF/ADF

Thanks.

BAO.SZ

I use the Actions-->branch feature.

But I cannot edit the first branched post, and you become the author of this thread.

Timo Hahn

BAZ, now things get messi

Your intention was good, however branching away the answer isn't something you, we or anybody should do. Now @"kdario" is in the drivers seat for this thread, not you. It's a flaw in the software that you can branch away part of the thread, not your fault.

Anyway I suggest that you open a new thread with your follow up question referring to the original thread. Abandon this one, please. We are happy to answer to the new thread.

Timo

BAO.SZ

Timo and kdario,

I'd glad to open a new thread for the topic. and thank you all very much for your patiences and kindness.

I think the 'Action-->.branch' is an useful feature when some improvement been made, that is:

When make the branching, the operator (which should be the author of the original thread) should be still the 'driver of the new thread',

and can edit the title and post content for the new thread.(but now cannot).

The benefit of above feature is :

1. the new thread usaually will have some relation with the original one, so keep the relation between them will make the contents/threads in this forum more relevent.

A relevant connected network of information will be more useful than a vast volume of unrelated segements of posts.

2.little inputing will be needed by branch if the author can edit the original branch out post.


Timo Hahn

I agree with you, however this is not the right place to discuss this. There is already an enhancement request (idea as it called in the new forum wording) for this at where you can add your comment and vote for the request to get implemented.

Timo

1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 20 2013
Added on May 22 2013
2 comments
1,708 views