[xquery-talk] returning elements without duplicates, based on an XML schema and using an attribute as context node

G. Ken Holman gkholman at CraneSoftwrights.com
Thu Mar 26 18:08:08 PST 2009


At 2009-03-26 10:49 -0500, Philip Cantin wrote:
>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']))
>then (
>    for $ref in 
> distinct-values($schema//xs:element[exists(@maxOccurs) and 
> @maxOccurs != '1' and @maxOccurs ne 'unbounded']/@ref)
>...
>Can someone show me the proper way to access the maxOccurs attribute 
>from the ref attribute,

   $ref/../@maxOccurs

>and/or provide me with a link that can help me understand this 
>situation a little more?

All attributes are attached to an element ... the element is the 
attribute's parent ... "sibling" attributes are attached to the same 
parent.  So the address I gave to you goes to the attribute's 
parent's attached maxOccurs attribute.

I hope this helps.

. . . . . . . . . . . Ken

--
XQuery/XSLT/XSL-FO training in Los Angeles (New dates!) 2009-06-08
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman at CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



More information about the talk mailing list