[xquery-talk] 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 10:49:50 PST 2009
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']))
then (
for $ref in distinct-values($schema//xs:element[exists(@maxOccurs) and
@maxOccurs != '1' and @maxOccurs ne 'unbounded']/@ref)
let $name := string($ref)
let $max := string($ref//following-sibling::maxOccurs)
let $index_max := ($max cast as xs:integer)
return
<xf:bind
id="{concat($name, '-add-trigger')}"
nodeset="instance('views')/{$name}-add-trigger"
relevant="instance('save-data')//{$name}[{$index_min}]" />
)
else ()
};
and the XML schema code looks (very) roughly like this - and the only
purpose of showing this is to help illustrate what I'd like to do:
<xs:schema>
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="e" maxOccurs="2" />
<xs:element ref="g" maxOccurs="3" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:sequence>
<xs:element ref="j" maxOccurs="2" />
<xs:element ref="g" maxOccurs="3" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
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?
Thanks much in advance!
~PJC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090326/3c4b0ead/attachment.htm
More information about the talk
mailing list