How to get repeated element from For-Each in XSLT 2.0



I want to get repeated elements in XSLT 2.0. But there is a restriction that i have to do that only with using "For-each" loop.


Input XML:



<Data>
<Movie>
<name>A</name>
<writer>B</writer>
<writer>C</writer>
<director>D</director>
</Movie>
<Movie>
<name>A</name>
<writer>B</writer>
<writer>C</writer>
<director>D</director>
</Movie>
</Data>


Expected Output XML:



<Imdb>
<Film>
<writer>B</writer>
<writer>C</writer>
</Film>
<Film>
<writer>B</writer>
<writer>C</writer>
</Film>
</Imdb>


Current Output:



<?xml version="1.0" encoding="UTF-8"?>
<Imdb>
<Film>
<writer>B</writer>
<writer>B</writer>
</Film>
</Imdb>


MyXSLT:



<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="Data">
<Film>

<xsl:for-each select="Movie">
<writer>
<xsl:value-of select="writer" />
</writer>
</xsl:for-each>
</Film>

</xsl:template>
</xsl:stylesheet>


Note:


I need to achieve the above mentioned task only with for each loop or for each group by loop. So anyone can please help.


No comments:

Post a Comment