Max occurs of element which depend on value of other element using XML Schema
<p>I would need help with XML Schema. I would like to write some condition where max occurs of element depend on value of other element</p>

<p>My XML:</p>

<pre><code>&lt;databaza&gt;
&lt;dvd&gt;
    &lt;id&gt;01&lt;/id&gt;
    &lt;type&gt;DVD-R&lt;/type&gt;
    &lt;number_of_movies&gt;2&lt;/number_of_movies&gt;
    &lt;movie&gt;
        &lt;movie_id&gt;1&lt;/movie_id&gt;
        &lt;movie_name&gt;X-man&lt;/movie_name&gt;
        &lt;number_of_characters&gt;2&lt;/number_of_characters&gt;
        &lt;character&gt;
            &lt;character_id&gt;1&lt;/character_id&gt;
            &lt;character_name&gt;Andy Dufresne&lt;/character_name&gt;
            &lt;main_character&gt;YES&lt;/main_character&gt;
            &lt;performer&gt;Tim Robbins&lt;/performer&gt;      
        &lt;/character&gt;
        &lt;character&gt;
            &lt;character_id&gt;2&lt;/character_id&gt;
            &lt;character_name&gt;Rede&lt;/character_name&gt;
            &lt;main_character&gt;YES&lt;/main_character&gt;
            &lt;performer&gt;Morgan Freeman&lt;/performer&gt;       
        &lt;/character&gt;
    &lt;/movie&gt;
    &lt;movie&gt;
        &lt;movie_id&gt;2&lt;/movie_id&gt;
        &lt;movie_name&gt;Forrest Gump&lt;/movie_name&gt;
        &lt;number_of_characters&gt;4&lt;/number_of_characters&gt;
        &lt;character&gt;
            &lt;character_id&gt;1&lt;/character_id&gt;
            &lt;character_name&gt;Forrest Gump&lt;/character_name&gt;
            &lt;main_character&gt;YES&lt;/main_character&gt;
            &lt;performer&gt;Tom Hanks&lt;/performer&gt;        
        &lt;/character&gt;
        &lt;character&gt;
            &lt;character_id&gt;2&lt;/character_id&gt;
            &lt;character_name&gt;Jenny Curran&lt;/character_name&gt;
            &lt;main_character&gt;YES&lt;/main_character&gt;
            &lt;performer&gt;Robin Wright&lt;/performer&gt;     
        &lt;/character&gt;
        &lt;character&gt;
            &lt;character_id&gt;3&lt;/character_id&gt;
            &lt;character_name&gt;Bubba&lt;/character_name&gt;
            &lt;main_character&gt;YES&lt;/main_character&gt;
            &lt;performer&gt;Mykelti Williamson&lt;/performer&gt;       
        &lt;/character&gt;
        &lt;character&gt;
            &lt;character_id&gt;4&lt;/character_id&gt;
            &lt;character_name&gt;Dan Taylor&lt;/character_name&gt;
            &lt;main_character&gt;YES&lt;/main_character&gt;
            &lt;performer&gt;Gary Sinise&lt;/performer&gt;      
        &lt;/character&gt;
    &lt;/movie&gt;
&lt;/dvd&gt;
&lt;/databaza&gt;
</code></pre>

<p>I need some condition which say that the number of <code>&lt;movie&gt;</code> depends on <code>&lt;number_of_movies&gt;</code> and then that the number of <code>&lt;character&gt;</code> depends on <code>&lt;number_of_characters&gt;</code></p>

<p>And how can I write the condition which say that the <code>&lt;character_id&gt;</code> going from 1 to max <code>&lt;number_of_characters&gt;</code> and the same condition for <code>&lt;movie_id&gt;</code>?</p>