For this xml:
<G>
<P>
<A>
<b>value b</b>
<c>value c</c>
</A>
<A>
<b>value b2</b>
<c>value c2</c>
</A>
<D>value ew</D>
<D>value e2</D>
<E>value f</E>
</P>
<P>
<A>
<b>value bx</b>
<c>value cx</c>
</A>
<A>
<b>value b2x</b>
<c>value c2x</c>
</A>
<D>value exw</D>
<D>value ex2</D>
<D>value ex2</D>
<E>value fx</E>
</P>
</G>
The tags like A and D can occur multiple times , the original xml on which I am working has large number of tags and many of them have multiple occurences.
I have to genetrate output as :
value b value c value ew value f
value b value c value e2 value f
value b2 value c2 value ew value f
value b2 value c2 value e2 value f
value bx value cx value exw value fx
value bx value cx value ex2 value fx
value bx value cx value ex3 value fx
value b2x value c2x value exw value fx
value b2x value c2x value ex2 value fx
value b2x value c2x value ex3 value fx
This xslt generates correct output if A tag has multiple occurence ,but when other tags like D in above xml repeat this does not work.
<xsl:for-each select="//A">
<xsl:value-of select="b"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="c"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ancestor::P/D"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ancestor::P/E"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
Please suggest correct xslt
I think this can be achieved by using repeated calls to templates. First you have a template to match A but instead of outputting the b and c elements, you pass them as parameters to a template that matches the D elemenet
And then, within the the template that matches the D element, you concatenate the prefix with the value of D, and pass it to a template that matches the E element.
And then the template that matches the E element can output the whole string. Here is the full XSLT
When applied to your XML sample, the following is output