title: how to apply xs:unique to two objects
body: <p>I am trying to write xs:unique for my xsd to constrain the name for container and list objects have unique name, but could not make it work. Could you help? </p>
  
  <p>Here are the details</p>
  
  <p>My object structure is like the following tree.</p>
  
  <pre><code>App 
    |
    ---container
          |
           --list
                |
                 ---container
                       |
                       --list
  </code></pre>
  
  <p>Each "container " can have 0 or more "list" and each "list" can have 0 or more "container". Both list and container have "name" attribute and other different attributes. I would like to constrain that the "name" is unique for both container and list for the entire instance. How should I write the unique selector xpath? Here is the schema. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my_app="http://www.cisco.com/myapp" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
  &lt;xs:element name="app"&gt;
      &lt;xs:annotation&gt;
          &lt;xs:documentation&gt;Comment describing your root element&lt;/xs:documentation&gt;
      &lt;/xs:annotation&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="container" type="containerType"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:unique name="uniquename"&gt;
          &lt;xs:selector xpath=""/&gt;
          &lt;xs:field xpath="@name"/&gt;
      &lt;/xs:unique&gt;
  &lt;/xs:element&gt;
  &lt;xs:complexType name="listType"&gt;
      &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt;
          &lt;xs:element name="container" type="containerType"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute name="name"/&gt;
  &lt;/xs:complexType&gt;
  &lt;xs:complexType name="containerType"&gt;
      &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt;
          &lt;xs:element name="list" type="listType"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute name="name"/&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>