I have the following XML. Under the root node I have 'Search' node which holds configuration and 'Req' node which has Request. Inside 'Req' node there is a 'classId' node. I am storing the value I have a complex problem here. I have a 'appendString' node in my final result. First I need to check if a child node inside 'Req' node has value in it. If it has value I need to get the node name and match the node inside AllClass/class1/node3 and get its value and finally I need to form a String inside 'appendString' node like this 'Childname1=value1,Childname2=value2'. Please help.Thanks
My XML
<root>
<ns:Search xmlns:ns="http://example.com/1.0/">
<ns:AllClass>
<ns:class1>
<ns:node1>fhgfjh</ns:node1>
<ns:node2>Aprtyrtyril</ns:node2>
<ns:node3>
<ns:firstChild>Childname1</ns:firstChild>
<ns:SecondChild>Childname2</ns:SecondChild>
</ns:node3>
</ns:class1>
<ns:class2>
<ns:node1>dfgd</ns:node1>
<ns:node2>trytyu</ns:node2>
<ns:node3>
<ns:firstChild>Childname11</ns:firstChild>
<ns:SecondChild>Childname22</ns:SecondChild>
<ns:ThirdChild>Childname33</ns:ThirdChild>
</ns:node3>
</ns:class2>
.
.
.
.
.
.
</ns:AllClass>
</ns:Search>
<ns:Req xmlns:ns="http://example.com/1.0/">
<ns:classId>class1</ns:classId>
<ns:className>asdfg</ns:className>
<ns:firstChild>value1</ns:firstChild>
<ns:SecondChild>value2</ns:SecondChild>
<ns:ThirdChild></ns:ThirdChild>
<ns:FourthChild></ns:FourthChild>
.
.
.
.
.
</ns:Req>
</root>
XSL
<xsl:template match="root/Req">
<xsl:variable xmlns:ns="http://example.com/1.0/" name="class_tmp" select="/root/ns:Req/ns:classId" />
<xsl:variable name="class" select="concat('ns:',$class_tmp)" />
<ns1:Response xmlns:ns1="http://example.com/ns/">
<ns1:SearchString>
<xsl:value-of xmlns:ns="http://example.com/1.0/" xmlns:ns1="http://example.com/1.0/" select="/root/ns:Search/ns:AllClassM/*[name()=$class]/ns:node2" />
</ns1:SearchString>
<xsl:apply-templates/>
</ns1:Response>
</xsl:template>
<xsl:template match="root/Req/*">
<ns1:appendString></ns1:appendString>
</xsl:template>
Final XML
<ns1:Response xmlns:ns1="http://example.com/ns/">
<ns1:SearchString>Aprtyrtyril</ns1:SearchString>
<ns1:appendString>Childname1=value1,Childname2=value2</ns1:appendString>
</ns1:Response>