利用XML做自定义报表(1)---报表格式XML结构

 抛砖引玉,有更好处理的请留言

1 xml 结构

将报表行分为五个类型:标题,子标题,数据,合计,总计

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by opec (opec) -->
<!--W3C Schema generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
 <xs:simpleType name="YesNo">
  <xs:restriction base="xs:NMTOKEN">
   <xs:enumeration value="False"/>
   <xs:enumeration value="True"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="A_LCR">
  <xs:restriction base="xs:string">
   <xs:enumeration value=""/>
   <xs:enumeration value="Left"/>
   <xs:enumeration value="Center"/>
   <xs:enumeration value="Right"/>
   <xs:enumeration value="Justify"/>
   <xs:enumeration value="Char"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="A_TMB">
  <xs:restriction base="xs:string">
   <xs:enumeration value=""/>
   <xs:enumeration value="Top"/>
   <xs:enumeration value="Middle"/>
   <xs:enumeration value="Bottom"/>
   <xs:enumeration value="Baseline"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:element name="BR" type="xs:string"/>
 <xs:element name="Page">
  <xs:complexType/>
 </xs:element>
 <xs:complexType name="ValueType" mixed="true">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
   <xs:element ref="BR"/>
  </xs:choice>
 </xs:complexType>
 <xs:complexType name="ColumnType">
  <xs:choice minOccurs="0">
   <xs:element ref="Page"/>
   <xs:element name="Value" type="ValueType" minOccurs="0" maxOccurs="unbounded"/>
   <xs:element name="Table" type="TableType" minOccurs="0" maxOccurs="unbounded"/>
  </xs:choice>
  <xs:attribute name="Name" type="xs:string"/>
  <xs:attribute name="CssClass" type="xs:string"/>
  <xs:attribute name="Style" type="xs:string"/>
  <xs:attribute name="Width" type="xs:string"/>
  <xs:attribute name="Height" type="xs:string"/>
  <xs:attribute name="HAlign" type="A_LCR"/>
  <xs:attribute name="VAlign" type="A_TMB"/>
  <xs:attribute name="IsDisplay" type="YesNo" default="True"/>
  <xs:attribute name="IsDate" type="YesNo" default="False"/>
  <xs:attribute name="ColSpan" type="xs:string"/>
  <xs:attribute name="RowSpan" type="xs:string"/>
  <xs:attribute name="BgColor" type="xs:string"/>
  <xs:attribute name="BorderColor" type="xs:string"/>
  <xs:attribute name="OnClick" type="xs:string"/>
  <xs:attribute name="OnDbClick" type="xs:string"/>
  <xs:attribute name="DIndex" type="xs:string"/>
  <xs:attribute name="IsCount" type="YesNo" default="False"/>
 </xs:complexType>
 <xs:complexType name="DataRowType">
  <xs:sequence>
   <xs:element name="Column" type="ColumnType" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="CssClass" type="xs:string"/>
  <xs:attribute name="Style" type="xs:string"/>
  <xs:attribute name="Width" type="xs:string"/>
  <xs:attribute name="Height" type="xs:string"/>
  <xs:attribute name="HAlign" type="A_LCR"/>
  <xs:attribute name="VAlign" type="A_TMB"/>
  <xs:attribute name="BgColor" type="xs:string"/>
  <xs:attribute name="BorderColor" type="xs:string"/>
  <xs:attribute name="OnClick" type="xs:string"/>
  <xs:attribute name="OnDbClick" type="xs:string"/>
  <xs:attribute name="Type" default="Normal">
   <xs:simpleType>
    <xs:restriction base="xs:NMTOKEN">
     <xs:enumeration value="Count"/>
     <xs:enumeration value="Normal"/>
     <xs:enumeration value="Title"/>
     <xs:enumeration value="TotalCount"/>
     <xs:enumeration value="SubTitle"/>
    </xs:restriction>
   </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="IsDisplay" type="YesNo" default="True"/>
 </xs:complexType>
 <xs:complexType name="TableType">
  <xs:sequence>
   <xs:element name="DataRow" type="DataRowType" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="CssClass" type="xs:string"/>
  <xs:attribute name="Style" type="xs:string"/>
  <xs:attribute name="Width" type="xs:string"/>
  <xs:attribute name="Height" type="xs:string"/>
  <xs:attribute name="HAlign" type="A_LCR"/>
  <xs:attribute name="VAlign" type="A_TMB"/>
  <xs:attribute name="BgColor" type="xs:string"/>
  <xs:attribute name="BorderColor" type="xs:string"/>
  <xs:attribute name="CellPadding" type="xs:byte" default="0"/>
  <xs:attribute name="CellSpacing" type="xs:byte" default="0"/>
  <xs:attribute name="Border" type="xs:string"/>
  <xs:attribute name="ID" type="xs:string"/>
  <xs:attribute name="OnClick" type="xs:string"/>
  <xs:attribute name="OnDbClick" type="xs:string"/>
 </xs:complexType>
 <xs:element name="RecordSet">
  <xs:complexType>
   <xs:choice maxOccurs="unbounded">
    <xs:element ref="Page"/>
    <xs:element name="Table" type="TableType"/>
   </xs:choice>
  </xs:complexType>
 </xs:element>
</xs:schema>

2/ XSLT转TABLE

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by opec (opec) -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="Table">
  <table>
   <xsl:if test="@ID!=''">
    <xsl:attribute name="ID"><xsl:value-of select="@ID"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@CssClass!=''">
    <xsl:attribute name="Class"><xsl:value-of select="@CssClass"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Style!=''">
    <xsl:attribute name="Style"><xsl:value-of select="@Style"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@HAlign!=''">
    <xsl:attribute name="Align"><xsl:value-of select="@HAlign"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@VAlign!=''">
    <xsl:attribute name="VAlign"><xsl:value-of select="@VAlign"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Width!=''">
    <xsl:attribute name="Width"><xsl:value-of select="@Width"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Height!=''">
    <xsl:attribute name="Height"><xsl:value-of select="@Height"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@BgColor!=''">
    <xsl:attribute name="BgColor"><xsl:value-of select="@BgColor"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Border!=''">
    <xsl:attribute name="Border"><xsl:value-of select="@Border"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@BorderColor!=''">
    <xsl:attribute name="BorderColor"><xsl:value-of select="@BorderColor"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@CellPadding!=''">
    <xsl:attribute name="CellPadding"><xsl:value-of select="@CellPadding"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@CellSpacing!=''">
    <xsl:attribute name="CellSpacing"><xsl:value-of select="@CellSpacing"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@OnClick!=''">
    <xsl:attribute name="OnClick"><xsl:value-of select="@OnClick"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@OnDbClick!=''">
    <xsl:attribute name="OnDbClick"><xsl:value-of select="@OnDbClick"/></xsl:attribute>
   </xsl:if>
   <xsl:apply-templates/>
  </table>
 </xsl:template>
 <xsl:template match="DataRow">
  <tr>
   <xsl:if test="@CssClass!=''">
    <xsl:attribute name="Class"><xsl:value-of select="@CssClass"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Style!=''">
    <xsl:attribute name="Style"><xsl:value-of select="@Style"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@HAlign!=''">
    <xsl:attribute name="Align"><xsl:value-of select="@HAlign"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@VAlign!=''">
    <xsl:attribute name="VAlign"><xsl:value-of select="@VAlign"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Width!=''">
    <xsl:attribute name="Width"><xsl:value-of select="@Width"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@Height!=''">
    <xsl:attribute name="Height"><xsl:value-of select="@Height"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@BgColor!=''">
    <xsl:attribute name="BgColor"><xsl:value-of select="@BgColor"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@BorderColor!=''">
    <xsl:attribute name="BorderColor"><xsl:value-of select="@BorderColor"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@OnClick!=''">
    <xsl:attribute name="OnClick"><xsl:value-of select="@OnClick"/></xsl:attribute>
   </xsl:if>
   <xsl:if test="@OnDbClick!=''">
    <xsl:attribute name="OnDbClick"><xsl:value-of select="@OnDbClick"/></xsl:attribute>
   </xsl:if>
   <xsl:for-each select="Column[@IsDisplay='True']">
    <td>
     <xsl:if test="@CssClass!=''">
      <xsl:attribute name="Class"><xsl:value-of select="@CssClass"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@Style!=''">
      <xsl:attribute name="Style"><xsl:value-of select="@Style"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@ColSpan!=''">
      <xsl:attribute name="ColSpan"><xsl:value-of select="@ColSpan"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@RowSpan!=''">
      <xsl:attribute name="RowSpan"><xsl:value-of select="@RowSpan"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@HAlign!=''">
      <xsl:attribute name="Align"><xsl:value-of select="@HAlign"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@VAlign!=''">
      <xsl:attribute name="VAlign"><xsl:value-of select="@VAlign"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@Width!=''">
      <xsl:attribute name="Width"><xsl:value-of select="@Width"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@Height!=''">
      <xsl:attribute name="Height"><xsl:value-of select="@Height"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@BgColor!=''">
      <xsl:attribute name="BgColor"><xsl:value-of select="@BgColor"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@BorderColor!=''">
      <xsl:attribute name="BorderColor"><xsl:value-of select="@BorderColor"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@OnClick!=''">
      <xsl:attribute name="OnClick"><xsl:value-of select="@OnClick"/></xsl:attribute>
     </xsl:if>
     <xsl:if test="@OnDbClick!=''">
      <xsl:attribute name="OnDbClick"><xsl:value-of select="@OnDbClick"/></xsl:attribute>
     </xsl:if>
     <xsl:apply-templates/>
    </td>
   </xsl:for-each>
  </tr>
 </xsl:template>
 <xsl:template match="Value">
  <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="BR">
  <br/>
  <xsl:value-of select="."/>
 </xsl:template>
  <xsl:template match="Page">
  <p style="page-break-after:always"></p>
 </xsl:template>
</xsl:stylesheet>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

honkerhero

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值