[xquery-talk] Selecting everything before and after path, but without duplicated leafs

J. Zhang zhangjunte at gmail.com
Tue Feb 12 16:44:33 PST 2008


On Feb 11, 2008 5:47 PM, Florent Georges <lists at fgeorges.org> wrote:
> "J. Zhang" wrote:
>
>   Hi
>
> > XPST0003: XQuery syntax error in #...elected) then return
> >     <SELECT>{#: expected "else", found ">"
> > Static error(s) in query
>
> > I don't see any mistake in the syntax. The error is probably
> > generated by the "if" statement, I assume it can take a "return"?
>
>   Nop.  The format of if-else is:
>
>     if ( condition ) then
>       sequence-if
>     else
>       sequence-else
>
>   There is no 'return' keyword there.  Remember the aim of the
> instructions is to build a sequence, not to break the evaluation (then
> it will be maybe more clear why no 'return' keyword is needed).


Thanks!

I finally got it working, but one thing is missing: the attributes of
the elements. I absolutely cannot miss the atributes, as I use them in
my XSLT to construct an HTML file. This is my entire XQuery script (I
hope it is useful for someone else as well):

declare namespace readme = "readme";

declare function readme:processNode($e as node()) as node()* {
   let $path := readme:getXPath($e)
   return
      if($path = "path")
      then (
         for $c in $e
            return
               <d>
               <SELECT />
               <SELECT2> {$e}</SELECT2>
               </d>
      )
      else (
         typeswitch ($e)
         case element()
         return
         element {name($e)} {
         for $c in $e/child::node()
            return
               readme:processNode($c)
         }
         default return $e
      )
};

declare function readme:getXPath ( $node as node() ) as xs:string
{
    let $pathelements := for $a in $node/ancestor-or-self::*
    return
        if ( name($a) = "ead" ) then "/ead[1]"
        else concat(name($a), "[" ,
          count($a/preceding-sibling::*[name()=name($a)]) + 1, "]")
    return string-join( $pathelements, "/" )
};

for $item in doc("file.xml")/*
return
readme:processNode($item)


How do I include the attributes? I know something needs to be changed
in this line of the function processNode:

element {name($e)} {

I am not 100% familiar with the syntax of XQuery yet, so if someone
can help me out...

Thank you,

jz


>   Regards,
>
> --drkm
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>       ______________________________________________________________________________
> Yahoo! Mail : un mail innovant avec Messenger compatible Windows Live + stockage illimité. http://mail.yahoo.fr
>
>



More information about the talk mailing list