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

returning elements without duplicates, based on an XML schema and using an attribute as context node

Philip Cantin pjcantin at gmail.com
Thu Mar 26 13:12:44 PST 2009


  returning elements without duplicates
Michael and Ken,

Thanks a bunch for your responses and help!

 Michael, I'll try and illustrate a bit better what I was trying to do
earlier.

I want the XQuery to determine if the @maxOccurs attribute exists in an
<xs:element> tag somewhere in the schema, and its value isn't 1. If this is
true, then, for all elements that have a @ref attribute in the schema
(because we now know there's at least one), the XQuery should get the string
value of the element's @ref attribute (what I wanted $name to be), along
with the value of element's @maxOccurs attribute (what i wanted $max to be),
and lastly the string value of $max (what I wanted $index_max to be). Then
finally, I just wanted to use these three values within an <xf:bind> tag
that was to be returned.

Also, I wanted to respond to few of your comments:


## note the exists(@maxOccurs) is redundant here. @maxOccurs != 1 always
returns false if @maxOccurs does not exist.

## it might be worth using a variable here to save doing the search twice
(or writing it twice).

---Thanks for the advice; at the moment I was going for getting the query to
work first, and optimization second, but I'll definitely change these things
once everything works the way it should.


## if your query is schema-aware, then @ref is a QName. Otherwise, it is a
string in the lexical form of a QName. Theoretically, you should be looking
for unique QNames, not unique strings.

---When you say the "query is schema-aware," are you referring to the editor
I am using to process the query (I'm using Altova XMLSpy), or the actual
query itself?


## This is pretty strange. $ref is an atomic value, so you can't use it on
the lhs of "/" or "//". Perhaps you wanted the attribute node? But which
attribute node: you're dealing with a group of @ref attributes that have the
same value. If $ref were a ref attribute (which it isn't), then you could
get the
maxOccurs attribute as $ref/../@maxOccurs

---Yes, I knew that code was completely incorrect. I was attempting to show
you the direction I wanted to go with my XPath expression, which was to find
the 'maxOccurs' attribute in an element based on where the 'ref' attribute
within the same element was.


~PJC


On Thu, Mar 26, 2009 at 12:15 PM, Michael Kay <http://x-query.com/mailman/listinfo/talk> wrote:



______________________________
>
> __
>
>        From: http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] On
> Behalf Of Philip Cantin
>        Sent: 26 March 2009 15:50
>        To: http://x-query.com/mailman/listinfo/talk
>        Subject:  returning elements without duplicates,based
> on an XML schema and using an attribute as context node
>
>
>        Hello All,
>
>        I am new to this mailing list, as well as fairly new to XQuery and
> XPath (having learned it for a month or two). For the most part, I haven't
> had too much trouble editing an old XQuery document, until now.
>
>        I am trying to access the 'maxOccurs' attribute within the for-loop,
> where $ref is the 'ref' attribute, and return distinct <xf:bind> elements
> with no duplicate elements. However, I can't seem to set the $max variable
> properly using XPath functions, without getting an error. I imagine it must
> have something to do with setting/finding/using the current context.
>
>
>        The XQuery code looks like this:
>
>
>        if (exists($schema//xs:element[exists(@maxOccurs) and @maxOccurs !=
> '1']))
>
> ## note the exists(@maxOccurs) is redundant here. @maxOccurs != 1 always
> returns false if @maxOccurs does not exist.
>
>        then (
>           for $ref in
> distinct-values($schema//xs:element[exists(@maxOccurs) and @maxOccurs !=
> '1'
> and @maxOccurs ne 'unbounded']/@ref)
>
> ## it might be worth using a variable here to save doing the search twice
> (or writing it twice).
>
> ## if your query is schema-aware, then @ref is a QName. Otherwise, it is a
> string in the lexical form of a QName. Theoretically, you should be looking
> for unique QNames, not unique strings.
>
>              let $name := string($ref)
>              let $max := string($ref//following-sibling::maxOccurs)
>
> ## This is pretty strange. $ref is an atomic value, so you can't use it on
> the lhs of "/" or "//". Perhaps you wanted the attribute node? But which
> attribute node: you're dealing with a group of @ref attributes that have
> the
> same value.
>
> At this point I'm afraid I'm stuck, because you haven't given any clues
> about what the query is supposed to do, and it's hard to reverse engineer
> the requirements from incorrect code.
>
> >       Can someone show me the proper way to access the maxOccurs
> attribute
> from the ref attribute, and/or provide me with a link that can help me
> understand this situation a little more?
>
>
> If $ref were a ref attribute (which it isn't), then you could get the
> maxOccurs attribute as $ref/../@maxOccurs
>
> Michael Kay
> http://www.saxonica.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090326/5469080e/attachment.htm


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.