RE: how to write such xquery?

Thanks anyway.

 

Anyone else can help?

 

 

  _____  

From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of
Michael Kay
Sent: Saturday, March 06, 2004 4:01 PM
To: Chen Yabing; www-ql@w3.org
Subject: RE: how to write such xquery?

 

I tried, and found it surprisingly hard. Much easier in XSLT. My general
approach to questions on lists is that if it takes me more than two
minutes to answer, I leave it to someone with more time. Sorry!

 

Michael Kay

 

  _____  

From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of
Chen Yabing
Sent: 06 March 2004 02:42
To: Michael Kay; www-ql@w3.org
Subject: RE: how to write such xquery?

 

Thanks a lot.

 

Would you mind write an example query to produce the result by using the
recursive tree walk?

I understand how to use FLWOR to write queries, but quite new the
recursive tree walk and the function used in it.

 

 

 

  _____  

From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of
Michael Kay
Sent: Friday, March 05, 2004 10:52 PM
To: Chen Yabing; www-ql@w3.org
Subject: RE: how to write such xquery?

 

Your example creates a copy of the input in which all elements except <d
dno="d001"> have been copied. I can't see how this relates to the
problem as you have described it.

 

However, the general answer is that to do this kind of transformation
you need to use the same kind of technique as you would use in XSLT,
that is a recursive tree walk, but using functions rather than template
rules. As you process each level of the tree, you create a new element
node with the same name as the input node, and then apply the function
recursively to those children that you want to copy, excluding those you
want to discard.

 

Michael Kay

 

  _____  

From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of
Chen Yabing
Sent: 05 March 2004 12:29
To: www-ql@w3.org
Subject: how to write such xquery?

 

Suppose I have a document as follows:

 

<a ano="a001">

   <b bno="b001">

       <c cno="c001"/>

       <d dno="d001"/>

       <d dno="d002"/>

   </b>

   <b bno="b002">

       <c cno="c002"/>

       <d dno="d002"/>

   </b>

</a>

 

I would like to write a query to retrieve those elements from top to
down that has sub element <d> whose dno = "d002". That is, I want the
result like this:

 

<a ano="a001">

   <b bno="b001">

       <c cno="c001"/>

       <d dno="d002"/>

   </b>

   <b bno="b002">

       <c cno="c002"/>

       <d dno="d002"/>

   </b>

</a>

 

How to write such a query in a simple XQuery? Can I use filter function?

Thanks in advance.

Received on Saturday, 6 March 2004 03:04:24 UTC