[xquery-talk] Function and Query Evaluation with No XML Tags Error

Kevin Grover kevin at kevingrover.net
Thu Feb 28 18:18:39 PST 2008


On Thu, Feb 28, 2008 at 8:06 AM, Wei, Alice J. <ajwei at indiana.edu> wrote:
> Hi, Kevin:
>
>    I was referring to the fact that the way the functions inside the definition is written seems to be different even though it is attempting to achieve the same functionality for those queries that do not use user-defined functions
>
>    As for the code, I am not sure if it is because the structure you provided me is different from what I am doing here, but I still get duplicates.
>
>
> declare function local:unique-nodes-by-value($seq as element()*) as element()*
>  {
>   for $r in $seq[not(string(.)=string((child::*)[1]))]

you used 'child::' instead of 'preceding-sibling::' (from my example).
 That's why.

>    return $r
>
>  };
>
>
>
>  for $r in local:unique-nodes-by-value(collection("xmldb:exist://db/cbml")//ad/head[contains(upper-case(.), 'STAMP COLLECTING OUTFIT')])
>   let $para := $r/ancestor::ad//(div|p)
>   let $head := $r/ancestor::ad/child::head
>   let $note := $r/ancestor::ad/note
>  return <ad>{$head}
>             {$para}
>             {$note}
>        </ad>
>
>  Snippet of output:
>
>  <ad>
>  <head>Stamp Collecting Outfit</head>
>  <p>Packet of world stamps, 9 Triangles, 2 Diamonds, animals, insects, flowers, ships, etc. Plus packet of hinges, perf. guage. Only 25c. Plus, stamps for your examination from our approval service which can be cancelled anytime. Buy what you want or none and return those not wanted in 10 days.
>  <address>
>  <addressLine>L.W. Brown.</addressLine>
>  <addressLine>Dent. C</addressLine>
>  <addressLine>Marion. Mich. 49665</addressLine>
>  </address>
>  </p>
>  </ad>
>  <ad>
>  <head>Stamp Collecting Outfit</head>
>  <p>Packet of world stamps, 9 Triangles, 2 Diamonds, animals, insects, flowers, ships, etc. Plus packet of hinges, perf. guage. Only 25c. Plus, stamps for your examination from our approval service which can be cancelled anytime. Buy what you want or none and return those not wanted in 10 days.
>  <address>
>  <addressLine>L.W. Brown.</addressLine>
>  <addressLine>Dent. C</addressLine>
>  <addressLine>Marion. Mich. 49665</addressLine>
>  </address>
>  </p>
>  </ad>
>
>  XML:
>
>  <ad>
>  <head>Stamp Collecting Outfit</head>
>  <p>Packet of world stamps, 9 Triangles, 2 Diamonds, animals, insects, flowers, ships, etc. Plus packet of hinges, perf. guage. Only 25c. Plus, stamps for your examination from our approval service which can be cancelled anytime. Buy what you want or none and return those not wanted in 10 days.
>  <address>
>  <addressLine>L.W. Brown.</addressLine>
>  <addressLine>Dent. C</addressLine>
>  <addressLine>Marion. Mich. 49665</addressLine>
>  </address>
>  </p>
>  </ad>
>  <ad>
>  <head type ="main">1c</head>
>  <head type ="sub">Thousands of Beautiful Stamps</head>
>  <p>1c each and up&why pay more when you can get the best for less. Write today for approvals. PENNY STAMP Service.
>  <address>
>  <addressLine>P.O. Box 898,</addressLine>
>  <addressLine>Mariposa California 95338</addressLine>
>  </address>
>  </p>
>  </ad>
>  <ad>
>  <head>Stamp Collecting Outfit</head>
>  <p>Packet of world stamps, 9 Triangles, 2 Diamonds, animals, insects, flowers, ships, etc. Plus packet of hinges, perf. guage. Only 25c. Plus, stamps for your examination from our approval service which can be cancelled anytime. Buy what you want or none and return those not wanted in 10 days.
>  <address>
>  <addressLine>L.W. Brown.</addressLine>
>  <addressLine>Dent. C</addressLine>
>  <addressLine>Marion. Mich. 49665</addressLine>
>  </address>
>  </p>
>  </ad>
>  ======================================================
>
> Alice Wei
>  MIS 2008
>  School of Library and Information Science
>  Indiana University Bloomington
>  ajwei at indiana.edu
>  ________________________________________
>  From: kogrover at gmail.com [kogrover at gmail.com] On Behalf Of Kevin Grover [kevin at kevingrover.net]
>  Sent: Wednesday, February 27, 2008 6:40 PM
>
> To: Wei, Alice J.
>  Cc: talk at x-query.com
>  Subject: Re: [xquery-talk] Function and Query Evaluation with No XML Tags Error
>
>
>
> On Wed, Feb 27, 2008 at 2:41 AM, Wei, Alice J. <ajwei at indiana.edu> wrote:
>  Hi, Kevin:
>
>   Thanks, this does bring some help to what I am trying to work on now. To certain extent, I have this feeling that the syntax between XQuery functions and XQuery user-defined functions are somewhat different.
>
>  I'm not sure I understand this statement.  It seems that you're implying that the built-in functions and user function behave differently?  Or are used differently?  I don't think this the case.  I could for, example, write my own function that behaved like the built-in distinct-values function.
>
>
>   Your code does point out quite a few different options and the variety of errors I could be getting when I am not doing them correctly. It does do the trick.
>
>  Thanks for your help.
>
>
>  You're welcome.  I'm glad it helped.  I've learned a great deal about XQuery myself in the last couple of days (by trying to help someone else).
>
>  - Kevin
>
>


More information about the talk mailing list