Hey all,
I have an XML document that I am trying to convert to XML. My XML document is as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<report>
<salescodes>
<code>AAA</code>
<code>BBB</code>
</salescodes>
<title>This is the Title</title>
<headers>
<header>Mo 1 (Accum)</header>
<header>Mo 2</header>
<header>Mo 3</header>
<header>Mo 4</header>
<header>Mo 5</header>
<header>Mo 6</header>
<header>Mo 7</header>
<header>Mo 8</header>
<header>Mo 9</header>
</headers>
<models>
<model>
<plantid>#####</plantid>
<modelyear>Model Year 1</modelyear>
<total>81194</total>
<accum>45484</accum>
<months>
<month>6863</month>
<month>7744</month>
<month>8959</month>
<month>10137</month>
<month>2007</month>
<month>0</month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
</months>
</model>
<model>
<plantid>######</plantid>
<modelyear>Model Year 2</modelyear>
<total>82696</total>
<accum>74858</accum>
<months>
<month>7838</month>
<month>0</month>
<month>0</month>
<month>0</month>
<month>0</month>
<month>0</month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
<month></month>
</months>
</model>
</models>
</report>
I am using the following XSL file to translate my code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="report/title" /></title>
</head>
<body>
<h2><xsl:value-of select="report/title" /></h2>
<h3>
<xsl:for-each select="report/salescodes">
<xsl:value-of select="code" />,
</xsl:for-each>
</h3>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Requirements</th>
<xsl:for-each select="report/headers">
<th align="left"><xsl:value-of select="header" /></th>
</xsl:for-each>
<th align="left">Total</th>
</tr>
<xsl:for-each select="report/models">
<tr>
<td><xsl:value-of select="modelyear" /></td>
<td><xsl:value-of select="accum" /></td>
<xsl:for-each select="months">
<td><xsl:value-of select="month" /></td>
</xsl:for-each>
<td><xsl:value-of select="total" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Unfortunately, I am having some issues with my for-each loops. Most of the loops seem to iterate one time and then they die. I don’t understand why this is happening so I thought I would ask you all!
The following is the output of my translation:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title</title>
</head>
<body>
<h2>Title</h2>
<h3>AAA
</h3>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Requirements</th><th align="left">Mo 1 (Accum)</th><th align="left">Total</th>
</tr>
<tr>
<td></td><td></td><td></td>
</tr>
</table>
</body>
</html>
If anyone has any suggestions, I would love to hear them. Thank you for your time.