-- 作者:isay
-- 发布时间:5/20/2007 10:44:00 PM
-- [求助]请问关于xsl:template 的嵌套问题(含表格嵌套)[已解决]
我(新手)有一xml文档。想用 xsl 将它格式化输出。 有点类似于 stylus studio 2007 中 xml 的网格形式。 请问我的 xsl 文档应该怎么写 ? (我写的xsl在后面) (我写的怎么也不显示表格里嵌套的表格内容。就有表头而已) xml: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="FileCollection.xsl"?> <DirectioryXmlModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <hasChildDirectiory>true</hasChildDirectiory> <hasFile>true</hasFile> <DirectoryPath>F:\MP3</DirectoryPath> <ChildDirectioryCount>72</ChildDirectioryCount> <ChildFileCount>4</ChildFileCount> <directorys> <DirectioryXmlModel> <Name>Nightwish</Name> <hasChildDirectiory>true</hasChildDirectiory> <hasFile>true</hasFile> <DirectoryPath>F:\MP3\</DirectoryPath> <ChildDirectioryCount>2</ChildDirectioryCount> <ChildFileCount>1</ChildFileCount> <directorys> <DirectioryXmlModel> <Name>Wishmaster</Name> <hasChildDirectiory>false</hasChildDirectiory> <hasFile>true</hasFile> <DirectoryPath>F:\MP3\Nightwish</DirectoryPath> <ChildDirectioryCount>0</ChildDirectioryCount> <ChildFileCount>16</ChildFileCount> <directorys /> <files> <FileXmlModel> <FileExtentsion>.wma</FileExtentsion> <FileSize>6904654</FileSize> <FileName>01 She Is My Sin.wma</FileName> <FilePath>F:\MP3\Nightwish\Wishmaster</FilePath> </FileXmlModel> </files> </DirectioryXmlModel> <DirectioryXmlModel> <Name>Highest Hopes (The Best Of Nightwish-+DVD) [UK] Disc 1</Name> <hasChildDirectiory>false</hasChildDirectiory> <hasFile>true</hasFile> <DirectoryPath>F:\MP3\Nightwish</DirectoryPath> <ChildDirectioryCount>0</ChildDirectioryCount> <ChildFileCount>24</ChildFileCount> <directorys /> <files> <FileXmlModel> <FileExtentsion>.jpg</FileExtentsion> <FileSize>10842</FileSize> <FileName>AlbumArt_{69D655A1-12B9-4FD5-84C8-5C88EA5E154D}_Large.jpg</FileName> <FilePath>F:\MP3\Nightwish\Highest Hopes (The Best Of Nightwish-+DVD) [UK] Disc 1</FilePath> </FileXmlModel> </files> </DirectioryXmlModel> </directorys> <files> <FileXmlModel> <FileExtentsion>.ini</FileExtentsion> <FileSize>322</FileSize> <FileName>desktop.ini</FileName> <FilePath>F:\MP3\Nightwish</FilePath> </FileXmlModel> </files> </DirectioryXmlModel> </directorys> <files> <FileXmlModel> <FileExtentsion>.MP3</FileExtentsion> <FileSize>1396950</FileSize> <FileName>test.MP3</FileName> <FilePath>F:\MP3\</FilePath> </FileXmlModel> </files> </DirectioryXmlModel> ------------------------------------------------------------------- xsl : <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table border="1" > <tr> <td>路径</td> <td>有否有子目录</td> <td>是否有文件</td> <td>子目录数</td> <td>子文件数</td> </tr> <tr> <td> <xsl:value-of select="DirectioryXmlModel/DirectoryPath" /> </td> <td> <xsl:value-of select="DirectioryXmlModel/hasChildDirectiory" /> </td> <td> <xsl:value-of select="DirectioryXmlModel/hasFile" /> </td> <td> <xsl:value-of select="DirectioryXmlModel/ChildDirectioryCount" /> </td> <td> <xsl:value-of select="DirectioryXmlModel/ChildFileCount" /> </td> </tr> </table> <table border="1"> <xsl:apply-templates select="DirectioryXmlModel/directorys"/> <xsl:apply-templates select="DirectioryXmlModel/files" /> </table> </body> </html> </xsl:template> <xsl:template match="directorys" name="dirTp"> <table border="1"> <tr> <td>目录名</td> <td>路径</td> <td>有否有子目录</td> <td>是否有文件</td> <td>子目录数</td> <td>子文件数</td> <td>目录</td> <td>文件</td> </tr> <xsl:for-each select="DirectioryXmlModel"> <tr> <td> <xsl:value-of select="Name" /> </td> <td> <xsl:value-of select="DirectoryPath" /> </td> <td> <xsl:value-of select="hasChildDirectiory" /> </td> <td> <xsl:value-of select="hasFile" /> </td> <td> <xsl:value-of select="ChildDirectioryCount" /> </td> <td> <xsl:value-of select="ChildFileCount" /> </td> <td> <xsl:call-template name="dirTp"> <xsl:with-param name="directorypath" select="self::DirectioryXmlModel/directorys" /> </xsl:call-template> </td> <td> <xsl:call-template name="fileTp"> <xsl:with-param name="filepath" select="self::DirectioryXmlModel/files" /> </xsl:call-template> </td> </tr> </xsl:for-each> </table> </xsl:template> <xsl:template match="files" name="fileTp"> <table border="1"> <tr> <td>文件名</td> <td>扩展名</td> <td>文件大小(B)</td> <td>路径</td> </tr> <xsl:for-each select="FileXmlModel"> <tr> <td> <xsl:value-of select="FileName" /> </td> <td> <xsl:value-of select="FileExtentsion" /> </td> <td> <xsl:value-of select="FileSize" /> </td> <td> <xsl:value-of select="FilePath" /> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> [此贴子已经被作者于2007-5-23 12:39:42编辑过]
|