title: Conditions in XML schemas
body: <p>Consider the following (poorly designed?) XML document:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;command_result&gt;
  &lt;param name="protocol_version" value="3"/&gt;
  &lt;param name="player_state" value="navigator"/&gt;
  &lt;/command_result&gt;
  </code></pre>
  
  <p>What I want to do is create an XML schema (XSD format) that specifies the datatype of the <code>value</code> attribute based on the actual value of the <code>name</code> attribute.</p>
  
  <p>Example (pseudocode):</p>
  
  <pre><code>if (param name = "protocol_version") then (param value type="xs:integer")
  if (param name = "player_state") then (param value type="xs:string")
  </code></pre>
  
  <p>Is there a way, without modifying the source XML, to introduce such a conditional statement in the schema file? I've looked at various solutions, but all of them required changes to the source somehow (e.g. setting xsi:type).</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My current schema:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:element name="command_result"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="param" minOccurs="2" maxOccurs="unbounded"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:attribute name="name" type="xs:string" use="required"/&gt;
                          &lt;!-- the following line needs to be modified somehow --&gt;
                          &lt;xs:attribute name="value" type="xs:string" use="optional"/&gt;
                      &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>