Hello all. I am new to XSLT and I cant figure out how to solve this problem:

I have a XML source document looking like this:
<file>
<object>
<name>A</name>
<type>1</type>
</object>
<object>
<name>B</name>
<type>1</type>
</object>
<object>
<name>C</name>
<type>2</type>
</object>
...
</file>

where I only have the <type> 1 and 2 for sure and I dont know how many <objects> I have.
how can I transform it to a table like this using XSLT:

<table>
<tr><th> 1 </td><th> 2 </td></tr>
<tr><td> A </td><td> C </td></tr>
<tr><td> B </td><td> </td></tr>
...
</table>

thanks for all the help

2 param value for saving type1 type2
rekursiv template

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<xsl:apply-templates select="file"/>
	</xsl:template>
	<xsl:template match="file">
		<table border="black solid 5em">
			<tr>
				<th>1</th>
				<th>2</th>
			</tr>
			<xsl:call-template name="print">
				<xsl:with-param name="ktype1" select="//object[type=1]/name"/>
				<xsl:with-param name="ktype2" select="//object[type=2]/name"/>
				<xsl:with-param name="ztype1" select="count(//object[type=1]/name)"/>
				<xsl:with-param name="ztype2" select="count(//object[type=2]/name)"/>
			</xsl:call-template>
		</table>
	</xsl:template>
	<xsl:template name="print">
		<xsl:param name="ktype1"/>
		<xsl:param name="ktype2"/>
		<xsl:param name="ztype1"/>
		<xsl:param name="ztype2"/>
		<xsl:param name="counter">1</xsl:param>
		<xsl:param name="c">
			<xsl:choose>
				<xsl:when test="$ztype1&lt;=$ztype2">
					<xsl:value-of select="$ztype2"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$ztype1"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:param>
		<xsl:if test="$counter&lt;=$c">
			<tr>
				<td>
					<xsl:value-of select="$ktype1[$counter]"/>
				</td>
				<td>
					<xsl:value-of select="$ktype2[$counter]"/>
				</td>
			</tr>
			<xsl:call-template name="print">
				<xsl:with-param name="ktype1" select="$ktype1"/>
				<xsl:with-param name="ktype2" select="$ktype2"/>
				<xsl:with-param name="counter" select="$counter +1"/>
				<xsl:with-param name="c" select="$c"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

Helmut Hagemann

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.