title: Generate XPath using XPath
body: <p>I have two separate types of XML documents (one is <code>a.xml</code> &amp; the other is <code>b.xml</code>). Document <code>a.xml</code>, is my main source document, on which I have to run queries. Document <code>b.xml</code> contains all possible information to fetch records from <code>a.xml</code>.</p>
  
  <p><strong>Document: «a.xml»</strong>  </p>
  
  
  
  <pre><code>&lt;rs&gt;
      &lt;r id="r1"&gt;
          &lt;f0&gt;typeA&lt;/f0&gt;
          &lt;f1&gt;contains value1, value2 and value3&lt;/f1&gt;
      &lt;/r&gt;
      &lt;r id="r2"&gt;
          &lt;f0&gt;typeB&lt;/f0&gt;
          &lt;f1&gt;contains value4 and value7&lt;/f1&gt;
      &lt;/r&gt;
      &lt;r id="r3"&gt;
          &lt;f0&gt;typeA&lt;/f0&gt;
          &lt;f1&gt;contains value2 and value5&lt;/f1&gt;
      &lt;/r&gt;
      &lt;r id="r4"&gt;
          &lt;f0&gt;typeC&lt;/f0&gt;
          &lt;f1&gt;contains value1 and value6&lt;/f1&gt;
      &lt;/r&gt;
      &lt;r id="r5"&gt;
          &lt;f0&gt;typeA&lt;/f0&gt;
          &lt;f1&gt;contains value5&lt;/f1&gt;
      &lt;/r&gt;
      &lt;r id="r6"&gt;
          &lt;f0&gt;typeC&lt;/f0&gt;
          &lt;f1&gt;contains value1, value2 and value3&lt;/f1&gt;
      &lt;/r&gt;
  &lt;/rs&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Document: «b.xml»</strong>  </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;qs&gt;
      &lt;q id="q1"&gt;
          &lt;i0&gt;typeA&lt;/i0&gt;
          &lt;i1&gt;value1|value2|value3&lt;/i1&gt;
          &lt;i2&gt;value18|value35&lt;/i2&gt;
          &lt;i3&gt;value1|value7&lt;/i3&gt;
      &lt;/q&gt;
      &lt;q id="q2"&gt;
          &lt;i0&gt;typeB&lt;/i0&gt;
          &lt;i1&gt;value2|value7&lt;/i1&gt;
          &lt;i2&gt;value9|value20&lt;/i2&gt;
          &lt;i3&gt;value4&lt;/i3&gt;
      &lt;/q&gt;
  &lt;/qs&gt;
  </code></pre>
  
  <hr>
  
  <p>Now I like to generate dynamic <code>XPath selector strings</code> based on the values of <code>b.xml</code> to be stored in Document <code>c.xml</code>. And it would look like:  </p>
  
  <p><strong>Document <code>c.xml</code></strong></p>
  
  <pre><code>&lt;xps&gt;
      &lt;xp id="q1"&gt;
          &lt;t1&gt;/rs/r[contains(f0,'typeA') 
                  and contains(f1,'value1') 
                  and contains(f1,'value2') 
                  and contains(f1,'value3')]&lt;/t1&gt;
          &lt;t2&gt;/rs/r[contains(f0,'typeA') 
                  and contains(f1,'value18') 
                  and contains(f1,'value35')]&lt;/t2&gt;
          &lt;t3&gt;/rs/r[contains(f0,'typeA') 
                  and contains(f1,'value1') 
                  and contains(f1,'value7')]&lt;/t3&gt;
      &lt;/xp&gt;
      &lt;xp id="q2"&gt;
          &lt;t1&gt;/rs/r[contains(f0,'typeB') 
                  and contains(f1,'value2') 
                  and contains(f1,'value7')]&lt;/t1&gt;
          &lt;t2&gt;/rs/r[contains(f0,'typeA') 
                  and contains(f1,'value9') 
                  and contains(f1,'value20')]&lt;/t2&gt;
          &lt;t3&gt;/rs/r[contains(f0,'typeA') 
                  and contains(f1,'value4')]&lt;/t3&gt;
      &lt;/xp&gt;
  &lt;/xps&gt;
  </code></pre>
  
  <hr>
  
  <p>If somebody here having any idea, how to do that job in XSLT version 1.0. Thanks in advance.</p>