Re: Use Cases 1.2.4.1 (TREE-Q1): wrong solution

Hi Alberto!
I agree with you. TREE-Q1 is absolutely wrong!

But I don't think that your function will produce the expected output.
The ouutput must not contain the title of the book - only the titles of 
the sections. Therefore you have to check if the parent of the title is 
a section!

If have written 2 working versions of the function:
The first one uses the 'local-name()'-function.
The second one makes no use of the 'local-name()'-function and is more 
advanced.

{-- using local-name() --}
define function toc($e as element)
   as element*
{
   for $elt in $e/*
   let $n := local-name($elt)
   return
     if ($n = "section")
     then <section>
              { $elt/@* }
              { toc($elt) }
          </section>
     else if ($n = "title" and local-name($elt/..) = "section")
     then $elt
     else ()
}


{-- not using local-name() --}
define function toc($book as element) as element*
{
	for $section in $book/section,
	    $title   in $section/title
	return
		<section>
              	{ $section/@* , $title , toc($section) }			
		</section>
}


I hope, somebody will read this post and will remove this big, fat BUG ;-)

Michael W.

Received on Thursday, 6 March 2003 09:01:47 UTC