Michael and Ken,<br><br>Thanks a bunch for your responses and help!<br><br> Michael, I'll try and illustrate a bit better what I was trying to do earlier.<br><br>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.<br>
<br>Also, I wanted to respond to few of your comments:<div class="im"><br><br><br>
## note the exists(@maxOccurs) is redundant here. @maxOccurs != 1 always<br>
returns false if @maxOccurs does not exist.<br><br></div><div class="im">## it might be worth using a variable here to save doing the search twice<br>
(or writing it twice).<br><br></div>---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.<div class="im"><br>
<br><br>## if your query is schema-aware, then @ref is a QName. Otherwise, it is a<br>
string in the lexical form of a QName. Theoretically, you should be looking<br>
for unique QNames, not unique strings.<br><br></div>---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?<div class="im"><br>
<br><br>## This is pretty strange. $ref is an atomic value, so you can't use it on<br>
the lhs of "/" or "//". Perhaps you wanted the attribute node? But which<br>
attribute node: you're dealing with a group of @ref attributes that have the<br></div>
same value. If $ref were a ref attribute (which it isn't), then you could get the<div class="im"><br>
maxOccurs attribute as $ref/../@maxOccurs<br><br></div>---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.<br>
<br><br>~PJC<br><br><br>On Thu, Mar 26, 2009 at 12:15 PM, Michael Kay <span dir="ltr"><<a href="mailto:mike@saxonica.com" target="_blank">mike@saxonica.com</a>></span> wrote:<br>
<br>
<br>
<br>
______________________________<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">__<br>
<br>
From: <a href="mailto:talk-bounces@x-query.com" target="_blank">talk-bounces@x-query.com</a> [mailto:<a href="mailto:talk-bounces@x-query.com" target="_blank">talk-bounces@x-query.com</a>] On<br>
Behalf Of Philip Cantin<br>
Sent: 26 March 2009 15:50<br>
To: <a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br>
Subject: [xquery-talk] returning elements without duplicates,based<br>
on an XML schema and using an attribute as context node<br>
<div><br>
<br>
Hello All,<br>
<br>
I am new to this mailing list, as well as fairly new to XQuery and<br>
XPath (having learned it for a month or two). For the most part, I haven't<br>
had too much trouble editing an old XQuery document, until now.<br>
<br>
I am trying to access the 'maxOccurs' attribute within the for-loop,<br>
where $ref is the 'ref' attribute, and return distinct <xf:bind> elements<br>
with no duplicate elements. However, I can't seem to set the $max variable<br>
properly using XPath functions, without getting an error. I imagine it must<br>
have something to do with setting/finding/using the current context.<br>
<br>
<br>
The XQuery code looks like this:<br>
<br>
<br>
if (exists($schema//xs:element[exists(@maxOccurs) and @maxOccurs !=<br>
'1']))<br>
<br>
</div>## note the exists(@maxOccurs) is redundant here. @maxOccurs != 1 always<br>
returns false if @maxOccurs does not exist.<br>
<div><br>
then (<br>
for $ref in<br>
distinct-values($schema//xs:element[exists(@maxOccurs) and @maxOccurs != '1'<br>
and @maxOccurs ne 'unbounded']/@ref)<br>
<br>
</div>## it might be worth using a variable here to save doing the search twice<br>
(or writing it twice).<br>
<br>
## if your query is schema-aware, then @ref is a QName. Otherwise, it is a<br>
string in the lexical form of a QName. Theoretically, you should be looking<br>
for unique QNames, not unique strings.<br>
<div><br>
let $name := string($ref)<br>
let $max := string($ref//following-sibling::maxOccurs)<br>
<br>
</div>## This is pretty strange. $ref is an atomic value, so you can't use it on<br>
the lhs of "/" or "//". Perhaps you wanted the attribute node? But which<br>
attribute node: you're dealing with a group of @ref attributes that have the<br>
same value.<br>
<br>
At this point I'm afraid I'm stuck, because you haven't given any clues<br>
about what the query is supposed to do, and it's hard to reverse engineer<br>
the requirements from incorrect code.<br>
<div><br>
> Can someone show me the proper way to access the maxOccurs attribute<br>
from the ref attribute, and/or provide me with a link that can help me<br>
understand this situation a little more?<br>
<br>
<br>
</div>If $ref were a ref attribute (which it isn't), then you could get the<br>
maxOccurs attribute as $ref/../@maxOccurs<br>
<font color="#888888"><br>
Michael Kay<br>
<a href="http://www.saxonica.com/" target="_blank">http://www.saxonica.com/</a><br>
</font></blockquote>