Hi,
I am trying to transform some XML data using XSL. Essentially I have a bunch of invoices encoded in XML and I want to display them all in a browser. I need to convert an XSL sheet that is geared to display one invoice (with a slightly different data set) to display many invoices.
Here is an abbreviated version of the XML:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="invoice.xsl" type="text/xsl"?>
<database URL="jdbcdbc:flamingo">
<invoices QUERY="SELECT * FROM invoice WHERE shipToState = 'NSW'">
<invoices_rec>
<invoiceNum>102</invoiceNum>
<salesDate>30. Jul. 01</salesDate>
<shipToAddress>11 Hollsworth St</shipToAddress>
<shipToCity>Paramatta</shipToCity>
<shipToState>NSW</shipToState>
<shipToZip>2421</shipToZip>
<contactName>Sally</contactName>
<contactPhone>6789-4321</contactPhone>
</invoices_rec>
</invoices>
<lines QUERY="SELECT i.invoiceNum, l.prodCode, l.salesQty, p.prodName, p.prodDesc,
p.prodPrice, l.salesQty * p.prodPrice AS extendedPrice FROM invoice i INNER JOIN
(lines l INNER JOIN products p ON l.prodCode = p.prodCode) ON
i.invoiceNum = l.invoiceNum WHERE i.shipToState = 'NSW'">
<lines_rec>
<invoiceNum>102</invoiceNum>
<prodCode>FP002</prodCode>
<salesQty>20</salesQty>
<prodName>Flamingo Towels</prodName>
<prodDesc>Terry towling material printed with flamingos</prodDesc>
<prodPrice>$15.00</prodPrice>
<extendedPrice>$300.00</extendedPrice>
</lines_rec>
<lines_rec>
<invoiceNum>103</invoiceNum>
<prodCode>FP002</prodCode>
<salesQty>10</salesQty>
<prodName>Flamingo Towels</prodName>
<prodDesc>Terry towling material printed with flamingos</prodDesc>
<prodPrice>$15.00</prodPrice>
<extendedPrice>$150.00</extendedPrice>
</lines_rec>
</lines>
<bottom QUERY="SELECT i.invoiceNum, Sum(l.salesQty * p.prodPrice) AS subtotal FROM invoice i
INNER JOIN (lines l INNER JOIN products p ON l.prodCode = p.prodCode) ON
i.invoiceNum = l.invoiceNum
GROUP BY i.invoiceNum">
<bottom_rec>
<invoiceNum>102</invoiceNum>
<subtotal>$2,459.00</subtotal>
</bottom_rec>
<bottom_rec>
<invoiceNum>103</invoiceNum>
<subtotal>$2,026.00</subtotal>
</bottom_rec>
</bottom>
</database>
Here is the XSL style sheet with which I am working:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xslutput method="html" indent="yes"/>
<!-- Main rule -->
<xsl:template match="/">
<html>
<head>
<title>
Invoice
</title>
</head>
<body bgcolor="#FFFFFF">
<H2 align="right"><font color="blue">INVOICE</font></H2>
<table cellpadding="5" width="100%">
<tr valign="top">
<td width="15%">
<font color="blue">Ship To:</font>
</td>
<td width="35%">
<font size="-1">
<xsl:apply-templates select="*/*/invoices_rec"/>
</font>
</td>
<td width="15%">
<font color="blue">Bill To:</font>
</td>
<td width="35%">
<font size="-1">
<xsl:apply-templates select="*/*/billTo_rec"/>
</font>
</td>
</tr>
</table>
<p/>
<table border="1" bordercolor="blue" width="100%">
<tr bgcolor="blue">
<xsl:apply-templates select="*/orderec"/>
</tr>
<tr>
<xsl:apply-templates select="*/*/orderec_rec"/>
</tr>
</table>
<p/>
<table border="0" cellpadding="2" width="100%">
<xsl:apply-templates select="*/products[position()=1]"/>
<xsl:apply-templates select='/database/products/products_rec'/>
</table>
<hr size="3"/>
<div align="right">
<table width="40%">
<xsl:for-each select="*/buttom/*/*">
<tr>
<td>
<font color="blue"><xsl:value-of select="@NAME"/>:</font>
</td>
<td align="right">
<xsl:apply-templates/>
</td>
</tr>
</xsl:for-each>
</table>
</div>
</body>
</html>
</xsl:template>
<!-- Left header -->
<xsl:template match="invoices_rec">
<xsl:for-each select="./*">
<xsl:apply-templates/>
<br/>
</xsl:for-each>
</xsl:template>
<!-- Right header -->
<xsl:template match="shipTo_rec">
<xsl:for-each select="./*">
<xsl:apply-templates/>
<br/>
</xsl:for-each>
</xsl:template>
<!-- Main body for order -->
<xsl:template match="orderec_rec">
<xsl:for-each select="./*">
<td align="center">
<font color="black" size="-1">
<xsl:if test="@ISNULL">
 
</xsl:if>
<xsl:apply-templates/>
</font>
</td>
</xsl:for-each>
</xsl:template>
<!-- Main header for order -->
<xsl:template match="orderec">
<xsl:for-each select="./*/*">
<td align="center">
<font color="white" size="-1">
<xsl:value-of select="@NAME"/>:
</font>
</td>
</xsl:for-each>
</xsl:template>
<!-- Main Table -->
<xsl:template match="products">
<xsl:for-each select="./*[position()=1]">
<!-- Main Table header -->
<tr bgcolor="blue">
<xsl:for-each select="./*">
<td align="center">
<font color="white" size="-1">
<xsl:value-of select="@NAME"/>:
</font>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="products_rec">
<tr>
<xsl:for-each select="./*">
<td align="left">
<font color="black" size="-1">
<xsl:if test="@ISNULL">
 
</xsl:if>
<xsl:apply-templates/>
</font>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
Again, the XSL sheet is not written for the exact same data set, but should require only minor tweaking.
It seems that I should use a <xsl:for-each select="/*/*/invoice_rec> right after the <body> tag, but when I do that, instead of displaying multiple invoices nothing is displayed.
I would greatly appreciate a little insight into this. Thanks in a advance!
I am trying to transform some XML data using XSL. Essentially I have a bunch of invoices encoded in XML and I want to display them all in a browser. I need to convert an XSL sheet that is geared to display one invoice (with a slightly different data set) to display many invoices.
Here is an abbreviated version of the XML:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="invoice.xsl" type="text/xsl"?>
<database URL="jdbcdbc:flamingo">
<invoices QUERY="SELECT * FROM invoice WHERE shipToState = 'NSW'">
<invoices_rec>
<invoiceNum>102</invoiceNum>
<salesDate>30. Jul. 01</salesDate>
<shipToAddress>11 Hollsworth St</shipToAddress>
<shipToCity>Paramatta</shipToCity>
<shipToState>NSW</shipToState>
<shipToZip>2421</shipToZip>
<contactName>Sally</contactName>
<contactPhone>6789-4321</contactPhone>
</invoices_rec>
</invoices>
<lines QUERY="SELECT i.invoiceNum, l.prodCode, l.salesQty, p.prodName, p.prodDesc,
p.prodPrice, l.salesQty * p.prodPrice AS extendedPrice FROM invoice i INNER JOIN
(lines l INNER JOIN products p ON l.prodCode = p.prodCode) ON
i.invoiceNum = l.invoiceNum WHERE i.shipToState = 'NSW'">
<lines_rec>
<invoiceNum>102</invoiceNum>
<prodCode>FP002</prodCode>
<salesQty>20</salesQty>
<prodName>Flamingo Towels</prodName>
<prodDesc>Terry towling material printed with flamingos</prodDesc>
<prodPrice>$15.00</prodPrice>
<extendedPrice>$300.00</extendedPrice>
</lines_rec>
<lines_rec>
<invoiceNum>103</invoiceNum>
<prodCode>FP002</prodCode>
<salesQty>10</salesQty>
<prodName>Flamingo Towels</prodName>
<prodDesc>Terry towling material printed with flamingos</prodDesc>
<prodPrice>$15.00</prodPrice>
<extendedPrice>$150.00</extendedPrice>
</lines_rec>
</lines>
<bottom QUERY="SELECT i.invoiceNum, Sum(l.salesQty * p.prodPrice) AS subtotal FROM invoice i
INNER JOIN (lines l INNER JOIN products p ON l.prodCode = p.prodCode) ON
i.invoiceNum = l.invoiceNum
GROUP BY i.invoiceNum">
<bottom_rec>
<invoiceNum>102</invoiceNum>
<subtotal>$2,459.00</subtotal>
</bottom_rec>
<bottom_rec>
<invoiceNum>103</invoiceNum>
<subtotal>$2,026.00</subtotal>
</bottom_rec>
</bottom>
</database>
Here is the XSL style sheet with which I am working:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xslutput method="html" indent="yes"/>
<!-- Main rule -->
<xsl:template match="/">
<html>
<head>
<title>
Invoice
</title>
</head>
<body bgcolor="#FFFFFF">
<H2 align="right"><font color="blue">INVOICE</font></H2>
<table cellpadding="5" width="100%">
<tr valign="top">
<td width="15%">
<font color="blue">Ship To:</font>
</td>
<td width="35%">
<font size="-1">
<xsl:apply-templates select="*/*/invoices_rec"/>
</font>
</td>
<td width="15%">
<font color="blue">Bill To:</font>
</td>
<td width="35%">
<font size="-1">
<xsl:apply-templates select="*/*/billTo_rec"/>
</font>
</td>
</tr>
</table>
<p/>
<table border="1" bordercolor="blue" width="100%">
<tr bgcolor="blue">
<xsl:apply-templates select="*/orderec"/>
</tr>
<tr>
<xsl:apply-templates select="*/*/orderec_rec"/>
</tr>
</table>
<p/>
<table border="0" cellpadding="2" width="100%">
<xsl:apply-templates select="*/products[position()=1]"/>
<xsl:apply-templates select='/database/products/products_rec'/>
</table>
<hr size="3"/>
<div align="right">
<table width="40%">
<xsl:for-each select="*/buttom/*/*">
<tr>
<td>
<font color="blue"><xsl:value-of select="@NAME"/>:</font>
</td>
<td align="right">
<xsl:apply-templates/>
</td>
</tr>
</xsl:for-each>
</table>
</div>
</body>
</html>
</xsl:template>
<!-- Left header -->
<xsl:template match="invoices_rec">
<xsl:for-each select="./*">
<xsl:apply-templates/>
<br/>
</xsl:for-each>
</xsl:template>
<!-- Right header -->
<xsl:template match="shipTo_rec">
<xsl:for-each select="./*">
<xsl:apply-templates/>
<br/>
</xsl:for-each>
</xsl:template>
<!-- Main body for order -->
<xsl:template match="orderec_rec">
<xsl:for-each select="./*">
<td align="center">
<font color="black" size="-1">
<xsl:if test="@ISNULL">
 
</xsl:if>
<xsl:apply-templates/>
</font>
</td>
</xsl:for-each>
</xsl:template>
<!-- Main header for order -->
<xsl:template match="orderec">
<xsl:for-each select="./*/*">
<td align="center">
<font color="white" size="-1">
<xsl:value-of select="@NAME"/>:
</font>
</td>
</xsl:for-each>
</xsl:template>
<!-- Main Table -->
<xsl:template match="products">
<xsl:for-each select="./*[position()=1]">
<!-- Main Table header -->
<tr bgcolor="blue">
<xsl:for-each select="./*">
<td align="center">
<font color="white" size="-1">
<xsl:value-of select="@NAME"/>:
</font>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="products_rec">
<tr>
<xsl:for-each select="./*">
<td align="left">
<font color="black" size="-1">
<xsl:if test="@ISNULL">
 
</xsl:if>
<xsl:apply-templates/>
</font>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
Again, the XSL sheet is not written for the exact same data set, but should require only minor tweaking.
It seems that I should use a <xsl:for-each select="/*/*/invoice_rec> right after the <body> tag, but when I do that, instead of displaying multiple invoices nothing is displayed.
I would greatly appreciate a little insight into this. Thanks in a advance!