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

Selecting everything before and after path, but without duplicated leafs

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


  Selecting everything before and after path
On Feb 11, 2008 5:47 PM, Florent Georges <http://x-query.com/mailman/listinfo/talk> 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
>
>



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.