I have a XML file want to convert to a Table OR CSV by XSLT. I tried by Altova MapForce 2014to map the columns but still,not able to gen out the outcomes. thanks a lot.
You need two nested loops here:
...
<xsl:for-each select="Records/Person/NameDetails/Name">
<xsl:variable name="NameType" select="@NameType"/>
<xsl:variable name="FirstName" select="NameValue/FirstName"/>
<xsl:variable name="Surname" select="NameValue/Surname"/>
<xsl:for-each select="../../Descriptions/Description">
<tr>
<td><xsl:value-of select="../../@id"/></td>
<td><xsl:value-of select="../../@date"/></td>
<td><xsl:value-of select="../../Gender"/></td>
<td><xsl:value-of select="$NameType"/></td>
<td><xsl:value-of select="$FirstName"/></td>
<td><xsl:value-of select="$Surname"/></td>
<td><xsl:value-of select="@Description1"/></td>
<td><xsl:value-of select="@Description2"/></td>
<td><xsl:value-of select="@Description3"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
...
To avoid storing all name details in individual variables, you can do:
<xsl:for-each select="Records/Person/NameDetails/Name">
<xsl:variable name="name" select="."/>
<xsl:for-each select="../../Descriptions/Description">
<tr>
<td><xsl:value-of select="../../@id"/></td>
<td><xsl:value-of select="../../@date"/></td>
<td><xsl:value-of select="../../Gender"/></td>
<td><xsl:value-of select="$name/@NameType"/></td>
<td><xsl:value-of select="$name/NameValue/FirstName"/></td>
<td><xsl:value-of select="$name/NameValue/Surname"/></td>
<td><xsl:value-of select="@Description1"/></td>
<td><xsl:value-of select="@Description2"/></td>
<td><xsl:value-of select="@Description3"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
Here's an example of 3 nested loops, adding the dates you have added in your latest edit.
<xsl:for-each select="Records/Person/NameDetails/Name">
<xsl:variable name="name" select="."/>
<xsl:for-each select="../../DateDetails/Date/DateValue">
<xsl:variable name="dateval" select="."/>
<xsl:for-each select="../../../Descriptions/Description">
<tr>
<td><xsl:value-of select="../../@id"/></td>
<td><xsl:value-of select="../../@date"/></td>
<td><xsl:value-of select="../../Gender"/></td>
<td><xsl:value-of select="$name/@NameType"/></td>
<td><xsl:value-of select="$name/NameValue/FirstName"/></td>
<td><xsl:value-of select="$name/NameValue/Surname"/></td>
<td><xsl:value-of select="@Description1"/></td>
<td><xsl:value-of select="@Description2"/></td>
<td><xsl:value-of select="@Description3"/></td>
<td><xsl:value-of select="$dateval/../@DateType"/></td>
<td><xsl:value-of select="$dateval/@Year"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
Here's how you can accomplish this using templates. To increase the number of levels of permutations, you'll just need to increase the number of templates, and pass more and more parameters from one to the next:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/*">
<html>
<head>
<title>Records</title>
</head>
<body>
<table border="1">
<tr>
<th>ID</th>
<th>date</th>
<th>Gender</th>
<th>NameType</th>
<th>FirstName</th>
<th>SurName</th>
<th>Description1</th>
<th>Description2</th>
<th>Description3</th>
<th>DateType</th>
<th>Year</th>
</tr>
<xsl:apply-templates select="Person" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Person">
<xsl:apply-templates select=".//Date/DateValue" />
</xsl:template>
<xsl:template match="DateValue">
<xsl:apply-templates select="ancestor::Person/NameDetails/Name">
<xsl:with-param name="date" select="." />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Name">
<xsl:param name="date" select="/.." />
<xsl:apply-templates select="ancestor::Person/Descriptions/Description">
<xsl:with-param name="date" select="$date" />
<xsl:with-param name="name" select="." />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Description">
<xsl:param name="date" select="/.." />
<xsl:param name="name" select="/.." />
<tr>
<td>
<xsl:value-of select="../../@id"/>
</td>
<td>
<xsl:value-of select="../../@date"/>
</td>
<td>
<xsl:value-of select="../../Gender"/>
</td>
<td>
<xsl:value-of select="$name/@NameType"/>
</td>
<td>
<xsl:value-of select="$name/NameValue/FirstName"/>
</td>
<td>
<xsl:value-of select="$name/NameValue/Surname"/>
</td>
<td>
<xsl:value-of select="@Description1"/>
</td>
<td>
<xsl:value-of select="@Description2"/>
</td>
<td>
<xsl:value-of select="@Description3"/>
</td>
<td>
<xsl:value-of select="$date/../@DateType"/>
</td>
<td>
<xsl:value-of select="$date/@Year"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>