output a table without loop
File: Data.xml
<?xml version="1.0" ?>
<customer-list>
<customer>
<name>
<first>A</first>
<last>B</last>
</name>
<order>C</order>
<order>D</order>
</customer>
</customer-list>
File: Transform.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Customers</TITLE>
</HEAD>
<BODY>
<TABLE BORDER="1" >
<xsl:apply-templates select="customer-list/customer" />
</TABLE>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="customer">
<TR><TH ALIGN="left">
<xsl:apply-templates select="name"/>
</TH></TR>
<xsl:apply-templates select="order"/>
</xsl:template>
<xsl:template match="order">
<TR><TD>
<xsl:apply-templates/>
</TD></TR>
</xsl:template>
<xsl:template match="name">
<xsl:value-of select="last" />,
<xsl:value-of select="first" />
</xsl:template>
</xsl:stylesheet>
Output:
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Customers</TITLE>
</HEAD>
<BODY>
<TABLE BORDER="1">
<TR>
<TH ALIGN="left">B,
A
</TH>
</TR>
<TR>
<TD>C</TD>
</TR>
<TR>
<TD>D</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Related examples in the same category