Hello All,<br><br>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&#39;t 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, where $ref is the &#39;ref&#39; attribute, and return distinct &lt;xf:bind&gt; elements with no duplicate elements. However, I can&#39;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. <br>
<br><br>The XQuery code looks like this:<br><br><br>if (exists($schema//xs:element[exists(@maxOccurs) and @maxOccurs != &#39;1&#39;]))<br>then (<br>   for $ref in distinct-values($schema//xs:element[exists(@maxOccurs) and @maxOccurs != &#39;1&#39; and @maxOccurs ne &#39;unbounded&#39;]/@ref)<br>
      let $name := string($ref)<br>      let $max := string($ref//following-sibling::maxOccurs)<br>      let $index_max := ($max cast as xs:integer)<br>      return<br>         &lt;xf:bind<br>            id=&quot;{concat($name, &#39;-add-trigger&#39;)}&quot;<br>
            nodeset=&quot;instance(&#39;views&#39;)/{$name}-add-trigger&quot;<br>            relevant=&quot;instance(&#39;save-data&#39;)//{$name}[{$index_min}]&quot; /&gt;<br><br>)<br>else ()<br>};<br><br><br>and the XML schema code looks (very) roughly like this - and the only purpose of showing this is to help illustrate what I&#39;d like to do:<br>
<br>&lt;xs:schema&gt;<br><br>   &lt;xs:element name=&quot;a&quot;&gt;<br>      &lt;xs:complexType&gt;<br>         &lt;xs:sequence&gt;<br>            &lt;xs:element ref=&quot;e&quot; maxOccurs=&quot;2&quot; /&gt;<br>            &lt;xs:element ref=&quot;g&quot; maxOccurs=&quot;3&quot; /&gt;<br>
         &lt;/xs:sequence&gt;<br>      &lt;/xs:complexType&gt;<br>   &lt;/xs:element&gt;<br><br>   &lt;xs:element name=&quot;b&quot;&gt;<br>
      &lt;xs:complexType&gt;<br>
         &lt;xs:sequence&gt;<br>
            &lt;xs:element ref=&quot;j&quot; maxOccurs=&quot;2&quot; /&gt;<br>
            &lt;xs:element ref=&quot;g&quot; maxOccurs=&quot;3&quot; /&gt;<br>
         &lt;/xs:sequence&gt;<br>
      &lt;/xs:complexType&gt;<br>
   &lt;/xs:element&gt;<br><br>&lt;/xs:schema&gt;<br><br><br>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?<br>
<br>Thanks much in advance!<br><br><br>~PJC<br>