September 2, 2016 at 3:06 pm
I have a query the creates the XML below. I am trying to format the output with xslt into a email with a heading, one table with inputs and another with update stats. The problem I an having is the second table is there with no data. So I end up with "Update Stats" the column heading and nothing.
Database Updated
Load for: 2016-08-23
File Name File Date Records in
2016-08-23 2016-01-21 1451238
Update Stats
Unmatched Invld. op Dups OR Applied
51592 0 312 0 1399334
<Order>
<oh>
<AccumDate>2016-08-23</AccumDate>
<TotalReturns>1451238</TotalReturns>
<FileName>fsb8n14648.pkg </FileName>
<FileDate>2016-08-23</FileDate>
<ReturnsCnt>1451238</ReturnsCnt>
<q>
<Not_Traced>51592</Not_Traced>
<OpCd_000>0</OpCd_000>
<Dup_Cnt>312</Dup_Cnt>
<UnMatched_Mail>0</UnMatched_Mail>
<Applied>1399334</Applied>
</q>
</oh>
</Order>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Order">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: segoe ui, tahoma, sans-serif;}
h1{color: #000;}
h2{size: 70%; color: #00f;}
td{padding-left:10px; padding-right: 10px;}
</style>
</head>
<body>
<h2>The Trace Returns database has been updated</h2>
<xsl:apply-templates select="oh"/>
</body>
</html>
</xsl:template>
<xsl:template match="oh">
<DIV style="margin-bottom:20px;">
<h2>
<p style="font-size: 70%;">
<a href="\\o2nas1\122nd_PA_PGM\IMB_Tracing\Trace_Return_Data_Conn.xlsx">\\o2nas1\122nd_PA_PGM\IMB_Tracing\Trace_Return_Data_Conn.xlsx</a>
</h2>
<h2>
Total Returns for <xsl:value-of select="AccumDate"/> : <xsl:value-of select="TotalReturns"/>
</h2>
<table border="1">
<tr>
<th>File Name</th>
<th>File Date</th>
<th >Total Returns</th>
</tr>
<xsl:apply-templates select="p"/>
</table>
<h2>Return Statistics</h2>
<table border="1">
<tr>
<th>Not Traced</th>
<th>Invaild Op Code</th>
<th>Duplicates</th>
<th>Expected IMB Missing</th>
<th>Applied</th>
</tr>
<xsl:apply-templates select="q"/>
</table>
</DIV>
<hr />
</xsl:template>
<xsl:template match="p">
<div style="color:#f00; font-size: 90%;">
<tr>
<td><xsl:value-of select="FileName"/></td>
<td><xsl:value-of select="FileDate"/></td>
<td align="right" ><xsl:value-of select="ReturnsCnt"/>
</td>
</tr>
</div>
</xsl:template>
<xsl:template match="p/q">
<div style="color:#f00; font-size: 90%;">
<tr>
<td align="right" ><xsl:value-of select="Not_Traced"/></td>
<td align="right" ><xsl:value-of select="OpCd_000"/></td>
<td align="right" ><xsl:value-of select="Dup_Cnt"/></td>
<td align="right" ><xsl:value-of select="UnMatched_Mail"/></td>
<td align="right" ><xsl:value-of select="Applied"/></td>
</tr>
</div>
</xsl:template>
<xsl:template match="NoRecords">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: tahoma, sans-serif;}
</style>
</head>
<body>
<h1>Daily Trace Return Totals</h1>
<div>
No Trace Returns were found for the specified date.
This does not mean there were no files.
It only states there were no updates.
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
September 3, 2016 at 2:51 am
Quick thought, add a test for the row in the table header template match, i.e changing
xsl:template match="oh"
to
xsl:template match="oh/q"
will eliminate the header for the "oh" if there are no "q" elements in the XML
😎
Edit: tidy up 😉
January 21, 2022 at 11:47 pm
I got this to work here is my final solution.
XML Document
<Stats>
<History>
<oh>
<FileType>Unmatched Future Mail Dates (Mailed Early?) </FileType>
<Mail_Date>2021-12-27</Mail_Date>
<Job_Num>1A22 </Job_Num>
<Mail_Cat>T</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>5</Total>
<Mail_Date>2021-12-27</Mail_Date>
<Job_Num>P102 </Job_Num>
<Mail_Cat>T</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>2</Total>
<Mail_Date>2022-01-07</Mail_Date>
<Job_Num>0107 </Job_Num>
<Mail_Cat>C</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>1</Total>
<Mail_Date>2022-01-28</Mail_Date>
<Job_Num>P896 </Job_Num>
<Mail_Cat>P</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>7</Total>
</oh>
<oh>
<FileType>Unmatched Past Mail Dates (Missing History?) </FileType>
<Mail_Date>2021-11-12</Mail_Date>
<Job_Num>1Q22 </Job_Num>
<Mail_Cat>T</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>3</Total>
<Mail_Date>2021-11-12</Mail_Date>
<Job_Num>O683 </Job_Num>
<Mail_Cat>P</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>2</Total>
<Mail_Date>2021-12-27</Mail_Date>
<Job_Num>1A22 </Job_Num>
<Mail_Cat>T</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>3</Total>
<Mail_Date>2021-12-27</Mail_Date>
<Job_Num>1B22 </Job_Num>
<Mail_Cat>T</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>2</Total>
<Mail_Date>2022-01-07</Mail_Date>
<Job_Num>0107 </Job_Num>
<Mail_Cat>C</Mail_Cat>
<Mail_Class>3</Mail_Class>
<Total>8</Total>
</oh>
</History>
</Stats>
XSL Trasnform
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="History">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: segoe ui, tahoma, sans-serif;}
h1{color: #000;}
h2{size: 70%; color: #00f;}
td{padding-left:10px; padding-right: 10px;}
</style>
</head>
<body>
Unmatched Trace Returns Report
<xsl:apply-templates select="oh"/>
</body>
</html>
</xsl:template>
<xsl:template match="oh">
<xsl:value-of select="FileType"/>
<table border="1">
<tr>
<th>Mail Date</th>
<th>Job Num</th>
<th>Mail Cat</th>
<th>Mail Class</th>
<th>Total</th>
</tr>
<xsl:apply-templates select="P"/>
</table>
</xsl:template>
<xsl:template match="P">
<tr>
<td><xsl:value-of select="Mail_Date"/></td>
<td><xsl:value-of select="Job_Num"/></td>
<td><xsl:value-of select="Mail_Cat"/></td>
<td><xsl:value-of select="Mail_Class"/></td>
<td align="right" ><xsl:value-of select="Total"/></td>
</tr>
</xsl:template>
<xsl:template match="NoRecords">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: tahoma, sans-serif;}
</style>
</head>
<body>
History Load Totals
No mail file were found for the specified date.
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply