[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

XQuery and id()/idref(); Controlling the children of nodes in the result sequence

Maik Stührenberg maik.stuehrenberg at uni-bielefeld.de
Wed Apr 23 14:21:10 PDT 2008


  XQuery and id()/idref(); Controlling the children of
	nodes in the result sequence
Hi Florent and Michael,

thanks for your response.

Florent Georges schrieb:
> Maik Stührenberg wrote:µ
> 
  >   You have to add the namespace nodes to the resultset
> element.  If the above example is a simplification, your
> real problem may require more complexity to select the
> namespace nodes to add, but from your example, you can
> choose to add the namespace nodes from each result/*.
> 
>   To see how to add a namespace node to an element, you can
> have a look at:
> 
> http://fgeorges.blogspot.com/2006/08/add-namespace-node-to-element-in.html
> 
>   You'll be interested too by the functions
> in-scope-prefixes() and namespace-uri-for-prefix().

Again, thanks to both of you. That problem was easy to solve.
> 
>   But first, I wonder if it is really worth writing that...
> 
>> - The biggest issue is that the b:para element is output
>> twice: as child element of the b:text element (which is
>> quite fine) and alone. The same problem appears when
>> looking at the c:word elements: they should not be
>> included as children of the c:sentence element because
>> they are related to different spans, but only as children
>> of the respective result element.
> 
>   I am not sure of the question.  If you want to "have an
> element without its children", you have to understand the
> XPath data model: child elements are part of their parent.

Well the problem is: the query should select all element nodes 
(including their children), if they share the same value of their a:span 
attribute (such as b:para and b:text -- vs. c:sentence and c:word where 
c:word is child of c:sentence but does refer to another a:span).

> If you want a parent that "looks the same" but without the
> children, you have to create a new element.  For instance,
> instead of:
> 
>     $d/a:collection/a:entry/a:data//*[@a:span = $s/@xml:id]
> 
> use rather:
> 
>     for $e in $d/a:collection/a:entry/a:data
>                 //*[@a:span = $s/@xml:id]
>       return
>         element { node-name($e) }{ $e/@* }

@Florent: Thanks for the hint, but in that case, the hierarchical 
relationship between b:text and b:para would get lost. Instead of getting

<b:text a:span="seg1">
  <b:para a:span="seg1"/>
</b:text>

the result is

<b:text a:span="seg1"/>
<b:para a:span="seg1"/>

@Michael: I'm aware that my path expression selects element nodes and 
their descendants, but there are cases in which this is necessary (if 
the descendants refer to the same a:span) -- and some in which not (if 
the descendants refer to different a:span elements than their ancestor).

So the question is, is it possible to recursively traverse the 
descendants of the a:data node and select only those element nodes which 
   refer to the same a:span element?

Regarding your answers to the idref() function: I will double check next 
time that the document is validated and that I use the -val:strict 
option in Saxon-SA.

Kind regards,

Maik Stührenberg




Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.