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