以前一直是我自已在用DataReport展示数据, 如今天随着数据越来越多, 我的同事也开始使用DataReport来展示数据了. 在他们使用的过程中, 渐渐显示出某些需要改进和完善的地方. 对于我的同事来讲, 编辑报表定义文件已不是问题, 但编辑用于控制报表显示的XSL文件则相当痛苦, 我也充分理解这种痛苦.

    比如让页面显示一排导航链接, 几经思量, 终于想出了一个解决的方法, 在报表定义中新增了一个属性.

WEBCHART.URLS=ID|URL[|Attributes]
              ID|URL[|Attributes]

    比如在报表定义文件中加入如下一行.

WEBCHART.URLS=Home|index.rhtml
              Sep|,|sep="1"
              Product|prod.rthml
              Sep|,|sep="1"
              About|about.rthml

    在生成的XML数据流中, 就会有如下数据.

- <urls>
  <url id="Home">index.rhtml</url>
  <url id="Sep" sep="1">,</url>
  <url id="Product">prod.rthml</url>
  <url id="Sep" sep="1">,</url>
  <url id="About">about.rthml</url>
  </urls>

    在XSL文件中, 就可以用统一的方式进行HTML转换.

......
<xsl:apply-templates select="urls" />
......
<xsl:template match="urls" >
    <div>
    <xsl:for-each select="url">
  <xsl:choose>
      <xsl:when test="@sep"> 
        <xsl:value-of select="." disable-output-escaping="yes" />
      </xsl:when>
      <xsl:otherwise> 
        <a>
          <xsl:attribute name="href">
              <xsl:value-of select="." />
          </xsl:attribute>
          <xsl:value-of select="@id" />
        </a>
      </xsl:otherwise>
  </xsl:choose>
    </xsl:for-each>
    </div>
</xsl:template>
......

    将原本需要在XSL中定义的内容, 移到报表定义文件的属性中, 增加XSL文件的通用性.