File: Data.xml
<?xml version="1.0" standalone="yes"?>
<report type="Unfilled Orders">
<customer number="CUST111" type="VIP">
<name>name 1</name>
<order-list count="2">
<order number="ORD200" owner="CUST111" total="650.00" status="late">
<item-list>
<item quantity="5" price="100">item 1</item>
<item quantity="2" price="50">item 2</item>
<item quantity="1" price="50">item 3</item>
</item-list>
</order>
<order number="ORD105" owner="CUST111" total="150.00" status="backordered">
<item-list>
<item quantity="6" price="25">item 4</item>
</item-list>
</order>
</order-list>
</customer>
<customer number="CUST222" type="normal">
<name>Alice Liddle</name>
<order-list count="2">
<order number="ORD102" owner="CUST222" total="3490.00" status="late">
<item-list>
<item quantity="20" price="100">item 1</item>
<item quantity="10" price="50">item 2</item>
<item quantity="10" price="50">item 3</item>
<item quantity="10" price="25">item 4</item>
<item quantity="2" price="120">item 5</item>
</item-list>
</order>
</order-list>
</customer>
</report>
File: Transform.xslt
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="report">
<HTML>
<BODY>
<FONT SIZE="6">
Report of <xsl:value-of select="@type" /> by Customer
</FONT>
<xsl:apply-templates select="customer" />
</BODY>
</HTML>
</xsl:template>
<xsl:template match="customer">
<HR/>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Customer #:</TH>
<TD><xsl:value-of select="@number" /></TD>
<TH>Name:</TH>
<TD><xsl:value-of select="name" /></TD>
<TH>Status:</TH>
<TD><xsl:value-of select="@type" /></TD>
</TR>
</TABLE>
<xsl:apply-templates select="order-list/order" />
</xsl:template>
<xsl:template match="order">
<P/>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Order #:</TH>
<TD><xsl:value-of select="@number" /></TD>
<TH>Status:</TH>
<TD><xsl:value-of select="@status" /></TD>
</TR>
</TABLE>
<TABLE BORDER="1" CELLPADDING="3" WIDTH="100%">
<TR ALIGN="left">
<TH>Quantity</TH>
<TH>Item</TH>
<TH ALIGN="right">Price</TH>
</TR>
<xsl:apply-templates select="item-list/item" />
</TABLE>
</xsl:template>
<xsl:template match="item">
<TR ALIGN="left">
<TD><xsl:value-of select="@quantity" /></TD>
<TD><xsl:value-of select="text()" /></TD>
<TD ALIGN="right"><xsl:value-of select="@price" /></TD>
</TR>
</xsl:template>
</xsl:stylesheet>
Output:
<HTML>
<BODY><FONT SIZE="6">
Report of Unfilled Orders by Customer
</FONT><HR>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Customer #:</TH>
<TD>CUST111</TD>
<TH>Name:</TH>
<TD>name 1</TD>
<TH>Status:</TH>
<TD>VIP</TD>
</TR>
</TABLE>
<P></P>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Order #:</TH>
<TD>ORD200</TD>
<TH>Status:</TH>
<TD>late</TD>
</TR>
</TABLE>
<TABLE BORDER="1" CELLPADDING="3" WIDTH="100%">
<TR ALIGN="left">
<TH>Quantity</TH>
<TH>Item</TH>
<TH ALIGN="right">Price</TH>
</TR>
<TR ALIGN="left">
<TD>5</TD>
<TD>item 1</TD>
<TD ALIGN="right">100</TD>
</TR>
<TR ALIGN="left">
<TD>2</TD>
<TD>item 2</TD>
<TD ALIGN="right">50</TD>
</TR>
<TR ALIGN="left">
<TD>1</TD>
<TD>item 3</TD>
<TD ALIGN="right">50</TD>
</TR>
</TABLE>
<P></P>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Order #:</TH>
<TD>ORD105</TD>
<TH>Status:</TH>
<TD>backordered</TD>
</TR>
</TABLE>
<TABLE BORDER="1" CELLPADDING="3" WIDTH="100%">
<TR ALIGN="left">
<TH>Quantity</TH>
<TH>Item</TH>
<TH ALIGN="right">Price</TH>
</TR>
<TR ALIGN="left">
<TD>6</TD>
<TD>item 4</TD>
<TD ALIGN="right">25</TD>
</TR>
</TABLE>
<HR>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Customer #:</TH>
<TD>CUST222</TD>
<TH>Name:</TH>
<TD>Alice Liddle</TD>
<TH>Status:</TH>
<TD>normal</TD>
</TR>
</TABLE>
<P></P>
<TABLE BORDER="1" CELLPADDING="3">
<TR ALIGN="left">
<TH>Order #:</TH>
<TD>ORD102</TD>
<TH>Status:</TH>
<TD>late</TD>
</TR>
</TABLE>
<TABLE BORDER="1" CELLPADDING="3" WIDTH="100%">
<TR ALIGN="left">
<TH>Quantity</TH>
<TH>Item</TH>
<TH ALIGN="right">Price</TH>
</TR>
<TR ALIGN="left">
<TD>20</TD>
<TD>item 1</TD>
<TD ALIGN="right">100</TD>
</TR>
<TR ALIGN="left">
<TD>10</TD>
<TD>item 2</TD>
<TD ALIGN="right">50</TD>
</TR>
<TR ALIGN="left">
<TD>10</TD>
<TD>item 3</TD>
<TD ALIGN="right">50</TD>
</TR>
<TR ALIGN="left">
<TD>10</TD>
<TD>item 4</TD>
<TD ALIGN="right">25</TD>
</TR>
<TR ALIGN="left">
<TD>2</TD>
<TD>item 5</TD>
<TD ALIGN="right">120</TD>
</TR>
</TABLE>
</BODY>
</HTML>
|