Michael and Ken,<br><br>Thanks a bunch for your responses and help!<br><br> Michael, I&#39;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
&lt;xs:element&gt; tag somewhere in the schema, and its value isn&#39;t 1.
If this is true, then, for all elements that have a @ref attribute in
the schema (because we now know there&#39;s at least one), the XQuery
should get the string value of the element&#39;s @ref attribute (what I
wanted $name to be), along with the value of element&#39;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 &lt;xf:bind&gt; 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&#39;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 &quot;query is schema-aware,&quot; are you referring to the editor I
am using to process the query (I&#39;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&#39;t use it on<br>
the lhs of &quot;/&quot; or &quot;//&quot;. Perhaps you wanted the attribute node? But which<br>
attribute node: you&#39;re dealing with a group of @ref attributes that have the<br></div>
same value. If $ref were a ref attribute (which it isn&#39;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 &#39;maxOccurs&#39; attribute in an element based on where the &#39;ref&#39;
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">&lt;<a href="mailto:mike@saxonica.com" target="_blank">mike@saxonica.com</a>&gt;</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&#39;t<br>
had too much trouble editing an old XQuery document, until now.<br>
<br>
        I am trying to access the &#39;maxOccurs&#39; attribute within the for-loop,<br>
where $ref is the &#39;ref&#39; attribute, and return distinct &lt;xf:bind&gt; elements<br>
with no duplicate elements. However, I can&#39;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>
&#39;1&#39;]))<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 != &#39;1&#39;<br>
and @maxOccurs ne &#39;unbounded&#39;]/@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&#39;t use it on<br>
the lhs of &quot;/&quot; or &quot;//&quot;. Perhaps you wanted the attribute node? But which<br>
attribute node: you&#39;re dealing with a group of @ref attributes that have the<br>
same value.<br>
<br>
At this point I&#39;m afraid I&#39;m stuck, because you haven&#39;t given any clues<br>
about what the query is supposed to do, and it&#39;s hard to reverse engineer<br>
the requirements from incorrect code.<br>
<div><br>
&gt;       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&#39;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>