首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xsl解析多层嵌套xml的有关问题()

2012-03-09 
xsl解析多层嵌套xml的问题(十万火急)xml文件:?xml version1.0 encodinggbk??xmlstylesheet type

xsl解析多层嵌套xml的问题(十万火急)
xml文件:
<?xml version="1.0" encoding="gbk"?>
<?xmlstylesheet type="text/xsl" href="b.xsl"?>
 <outRecords>
 <outRecord>
  <takeDept>ffgfgfggfgfg</takeDept> 
  <outDate>20111115</outDate> 
 <books>
 <book>
  <bookName>0000000</bookName> 
  <num>2</num> 
  </book>
  </books>
  </outRecord>
 <outRecord>
  <takeDept>2008房地产经营与估计1</takeDept> 
  <outDate>20110927</outDate> 
 <books>
 <book>
  <bookName>中国文化概论(附大纲)</bookName> 
  <num>1</num> 
  </book>
  </books>
  </outRecord>
 <outRecord>
  <takeDept>学员队</takeDept> 
  <outDate>20111115</outDate> 
 <books>
 <book>
  <bookName>111111</bookName> 
  <num>1</num> 
  </book>
 <book>
  <bookName>0000000</bookName> 
  <num>2</num> 
  </book>
 <book>
  <bookName>$张</bookName> 
  <num>11</num> 
  </book>
  </books>
  </outRecord>
 <outRecord>
  <takeDept>测试选修课班次</takeDept> 
  <outDate>20110928</outDate> 
 <books>
 <book>
  <bookName>百年航母风云</bookName> 
  <num>2</num> 
  </book>
  </books>
  </outRecord>
  </outRecords>

xsl文件:

<?xml version="1.0" encoding="gbk"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:variable name="SizeColWidth" select="40" />
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>takeDept</th>
<th>outDate</th>
<th>bookName</th>
<th>num</th>
</tr>

<xsl:for-each select="outRecords">
<tr>
<td>
<xsl:value-of select="."/>
</td>
<!--
<td>
<xsl:value-of select="outRecord/takeDept"/>
</td>
<td>
<xsl:value-of select="outRecord/outDate"/>
</td>
<td>
<xsl:value-of select="outRecord/books/book/bookName"/>
</td>
<td>
<xsl:value-of select="outRecord/books/book/num"/>
</td>
-->
</tr>

</xsl:for-each>


</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

我想把每个outRecord节点下的子项逐行输出,按照这个xml出来应该是有4行,但是我不知道怎么处理。现在写法的结果是一行一列。。。所有的数据都在同一个格子里,请大侠们帮帮忙

[解决办法]

HTML code
<?xml version="1.0" encoding="gbk"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">   <xsl:variable name="SizeColWidth" select="40" /><xsl:template match="/"><html> <body> <table border="1"> <tr bgcolor="#9acd32"> <th>takeDept</th> <th>outDate</th> <th>bookName</th> <th>num</th> </tr> <xsl:for-each select="outRecords/outRecord"> <tr> <td> <xsl:value-of select="takeDept"/> </td> <td> <xsl:value-of select="outDate"/> </td><xsl:for-each select="books/book"><td> <xsl:value-of select="bookName"/> </td><td> <xsl:value-of select="num"/> </td></xsl:for-each>    </tr> </xsl:for-each> </table> </body></html></xsl:template></xsl:stylesheet> 

热点排行