Practical examples of using XML to realize general WEB report printing

黄舟
Release: 2017-02-28 17:15:09
Original
1351 people have browsed it

A recent B/S project used a combination of embedding .net winform control and xml in IE when printing (see http://www.yesky.com/20030214/1652186.shtml ), in the actual application process, I have some experiences to share with you.

(1). Use a general template to format the XML file
There are three types of documents used in the system, namely the outbound order, the inbound order, and the delivery order. Therefore, three types of documents are defined. The template file has the following format

chukudan.xsl:

<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   
   <xsl:template match="Bill">   
   <root>
 <pagesetting>
  <landscape>false</landscape>
  <paperkind>Custom</paperkind>
  <paperwidth>800</paperwidth>
  <paperheight>600</paperheight>
  <paperleft>0</paperleft>
  <paperight>0</paperight>
  <papetop>0</papetop>
  <papebottom>0</papebottom>
 </pagesetting>
 <reporttable>
      <bill x="55" y="19" border="0" bordercolor="white" maxlines="6">
  <xsl:for-each select="BillMaster">
   <toptable width="743">
    <tr height="20">
<td width="118"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">车次号:</td>
<td width="449"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
<xsl:value-of select="SERIAL_NO" /></td>
     <td width="35"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"></td>
     <td width="138"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"></td>
    </tr>   
   </toptable> 
  </xsl:for-each> 
  <detailtable width="373">
   <xsl:for-each select="BillDetail">   
    <tr height="33">
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
     <xsl:value-of select="BILL_NO" />
     </td>
     <td width="173" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="PROD_MODEL_2" /></td>
     <td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
     <xsl:value-of select="PROD_NUM" /></td>
     <td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="PIECE_NUM" /></td>          
    </tr>  
   
   </xsl:for-each> 
  </detailtable>
  <mastertable width="370">
   <xsl:for-each select="BillMaster">
    <tr height="33">
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
     </td>
     <td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="ADDRESS" />
     </td>
    </tr>
    <tr height="33">
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
     <xsl:value-of select="CONTACT_PERSON" /></td>
     <td width="70" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="120" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
     <xsl:value-of select="CONTACT_PHONE" /></td>
    </tr>
    <tr height="33">        
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White">
     </td>
     <td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="DRIVER_UNIT" /></td>
    </tr>
    <tr height="33">
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="DRIVER_NO" /></td>
     <td width="70" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="120" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="DRIVER_PERSON" /></td>
    </tr>
    <tr height="33">
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="CAR_MODEL" />
     </td>
     <td width="70" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="120" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"></td>
    </tr>
    <tr height="33">
     <td width="90"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="COME_TO" /></td>
    </tr>
   </xsl:for-each> 
  </mastertable> 
  
  <foottable width="743">
   <xsl:for-each select="BillMaster">
    <tr height="35">
     <td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"></td>
     <td width="173" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"></td>
     <td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"></td>
     <td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"></td>          
    
     <td width="90"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     </td>
     <td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white">
     <xsl:value-of select="REMARK" /></td>
    </tr>  
   </xsl:for-each>
      </foottable>   
   
      </bill>
   </reporttable>
</root>     
   </xsl:template> 
</xsl:stylesheet>
Copy after login

Among them, toptable is the header, detailtable is the product details on the left side of the table, mastertable is the transportation information on the right side of the table, etc., and foottable is the bottom Tabulator and other information.

Then, in the asp.net page, convert the query results as follows

                                                                                                                                         ,,,,,,,,,,,,,,,,,,,,,,,,,’ Control:

 If billInfoXml <> Nothing Then
                billInfoDoc.LoadXml(billInfoXml)
                &#39;billInfoDoc.LoadXml("http://111.111.111.111/stockmg/test.xsl")
                billTrans.Load(billFormatXmlUrl)
                billXmlWr.Formatting = System.Xml.Formatting.Indented
                billXmlWr.Indentation = 4
                billXmlWr.IndentChar = " "
                billTrans.Transform(billNav, Nothing, billXmlWr, Nothing)
                billXmlWr.Flush()
            End If
Copy after login

Note that parent.frames is used to call the print control here.... This is to save the time of loading the print control every time the page is opened. A frame web page is used to print the The control is placed on a separate page so it does not need to be loaded each time.

The above is the content of practical examples of using XML to realize universal WEB report printing. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!