日期:2014-05-18  浏览次数:20429 次

Xsl参数如何传递
现在要把两张主从表的内容输入到excel文件中,通过xsl 来进行,主表是Father,子表是Child。给定主表的一个FatherID,在子表中找出所有与主表的FatherID相同的行,然后输入到excel中,样式如下图:
(照片不知道怎么上传)
父表FatherID 子表Name 子表FatherID
  长龙 1
1
  廉洁 1

其中在excel中“父表FatherID”下的1合并了两行,“子表Name”“子表FatherID”下的内容各占一行

Xml文档如下:
<?xml version="1.0" encoding="utf-8" ?>
<FCDataSet>
  <Child>
  <ChildID>1</ChildID>
  <Name>成龙</Name>
  <FatherID>1</FatherID>
  </Child>
  <Child>
  <ChildID>2</ChildID>
  <Name>廉洁</Name>
  <FatherID>1</FatherID>
  </Child>
  <Child>
  <ChildID>3</ChildID>
  <Name>刘娜</Name>
  <FatherID>2</FatherID>
  </Child>
  <Child>
  <ChildID>4</ChildID>
  <Name>礼物</Name>
  <FatherID>2</FatherID>
  </Child>
  <Father>
  <FatherID>1</FatherID>
  <Name>luo</Name>
  </Father>
  <Father>
  <FatherID>2</FatherID>
  <Name>长</Name>
  </Father>
</FCDataSet>
Xsl文件如下:
<xsl:template match="/">
  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:apply-templates/>
  </Workbook>
</xsl:template>

<xsl:template match="/*">
  <Worksheet>
<Table x:FullColumns="1" x:FullRows="1">
  <xsl:attribute name="ss:Name">
  <xsl:value-of select="local-name(/*/*)"/>
  </xsl:attribute>
<xsl:for-each select ="Father">
  <xsl:call-template name ="Fc">
  <xsl:with-param name ="FatherID">
  <xsl:value-of select ="FatherID"/>
  </xsl:with-param>
  </xsl:call-template>
  </xsl:for-each>
</Table>
  </Worksheet>
</xsl:template>

<xsl:template name="Fc">
  <xsl:param name ="FatherID" ></xsl:param>
  <xsl:for-each select ="Child[FatherID=$FatherID]">(这段代码问题出在这里,FatherID作为参数,并不能被传进来,而且现在即使在FatherID=后面直接设定值,也无法进行过滤)
  <Row>
  <Cell >
  <Data ss:Type="Number">
  <xsl:value-of select="ChildID"/>
  </Data>
  </Cell>
  <Cell >
  <Data ss:Type="String">
  <xsl:value-of select="Name"/>
  </Data>
  </Cell>
  </Row>  
  </xsl:for-each>
</xsl:template>
还想问各位大侠,在什么位置可以动态的合并“父表FatherID”下的单元格,使得它和后面的查出的子表中的行数相同。在线等,多多加分。


------解决方案--------------------
帮顶一下!