我有这个 XML 文件,我需要通过 xsl/t 将其转换为表格。
<?xml version="1.0" encoding="ISO-8859-1"?>
<TVGuide start="2001-07-05" end="2001-07-05">
<Channel>
<Name>BBC1</Name>
<Program>
<Start>2001-07-05T19:00:00</Start>
<Duration>PT30M</Duration>
<Series>A QuestionOfSport</Series>
<Title></Title>
</Program>
<Program rating="5" flag="favorite">
<Start>2001-07-05T19:30:00</Start>
<Duration>PT30M</Duration>
<Series>EastEnders</Series>
<Title></Title>
<Description>
Mark's health scare forces him to reconsider his future with Lisa,
while Jamie is torn between Sonia and Zoe.
</Description>
<CastList>
<CastMember>
<Character><Name>Zoe Slater</Name></Character>
<Actor><Name>Michelle Ryan</Name></Actor>
</CastMember>
<CastMember>
<Character><Name>Jamie Mitchell</Name></Character>
<Actor><Name>Jack Ryder</Name></Actor>
</CastMember>
<CastMember>
<Character><Name>Sonia Jackson</Name></Character>
<Actor><Name>Natalie Cassidy</Name></Actor>
</CastMember>
</CastList>
<Writers>
<Writer><Name>Nick Saltrese</Name></Writer>
<Writer><Name>Julie Wassmer</Name></Writer>
</Writers>
<Director><Name>Stewart Edwards</Name></Director>
<Producer><Name>Emma Turner</Name></Producer>
</Program>
<Program type="documentary">
<Start>2001-07-05T20:00:00</Start>
<Duration>PT45M</Duration>
<Series></Series>
<Title>Get Real with Casualty</Title>
</Program>
<Program>
<Start>2001-07-05T20:45:00</Start>
<Duration>PT45M</Duration>
<Series>Lottery</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T21:30:00</Start>
<Duration>PT1H</Duration>
<Series>Panorama</Series>
<Title></Title>
</Program>
</Channel>
<Channel>
<Name>BBC2</Name>
<Program>
<Start>2001-07-05T19:00:00</Start>
<Duration>PT1H</Duration>
<Series>Snooker</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T20:00:00</Start>
<Duration>PT1H</Duration>
<Series>HomeFront</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T21:00:00</Start>
<Duration>PT50M</Duration>
<Series>WildAfrica</Series>
<Title></Title>
</Program>
<Program flag="interesting">
<Start>2001-07-05T21:50:00</Start>
<Duration>PT40M</Duration>
<Series>Taboo</Series>
<Title>Nakedness</Title>
</Program>
</Channel>
<Channel>
<Name>ITV</Name>
<Program>
<Start>2001-07-05T19:00:00</Start>
<Duration>PT30M</Duration>
<Series>Emmerdale</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T19:30:00</Start>
<Duration>PT30M</Duration>
<Series>CoronationStreet</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T20:00:00</Start>
<Duration>PT1H</Duration>
<Series>Millionaire</Series>
<Title></Title>
</Program>
<Program type="drama">
<Start>2001-07-05T21:00:00</Start>
<Duration>PT2H</Duration>
<Series></Series>
<Title>Hot Money</Title>
</Program>
</Channel>
<Channel>
<Name>Channel 4</Name>
<Program>
<Start>2001-07-05T19:00:00</Start>
<Duration>PT55M</Duration>
<Series>Channel4News</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T19:55:00</Start>
<Duration>PT5M</Duration>
<Series>SlotArt</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T20:00:00</Start>
<Duration>PT30M</Duration>
<Series>Brookside</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T20:30:00</Start>
<Duration>PT30M</Duration>
<Series>Brookside</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T21:00:00</Start>
<Duration>PT1H</Duration>
<Series>Swallow</Series>
<Title></Title>
</Program>
<Program flag="favorite">
<Start>2001-07-05T22:00:00</Start>
<Duration>PT1H</Duration>
<Series>AllyMcBeal</Series>
<Title></Title>
</Program>
</Channel>
<Channel>
<Name>Channel 5</Name>
<Program>
<Start>2001-07-05T19:00:00</Start>
<Duration>PT30M</Duration>
<Series>MovieChartShow</Series>
<Title></Title>
</Program>
<Program>
<Start>2001-07-05T19:30:00</Start>
<Duration>PT30M</Duration>
<Series>FiveNews</Series>
<Title></Title>
</Program>
<Program type="entertainment">
<Start>2001-07-05T20:00:00</Start>
<Duration>PT1H</Duration>
<Series></Series>
<Title>The World's Worst Drivers Caught On Tape</Title>
</Program>
<Program type="film">
<Start>2001-07-05T21:00:00</Start>
<Duration>PT1H55M</Duration>
<Series></Series>
<Title>Black and White</Title>
</Program>
</Channel>
</TVGuide>
我知道问题可能出在 xsl 文件中。我不是专家,我会非常感谢您的帮助。
这是 xsl 文件。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="hatchala" match="/TVGuide/Channel/Program" use="Start"/>
<xsl:template match="/">
<table border="1">
<tr>hours
<xsl:call-template name="tvchan"/>
</tr>
<tr>
<th>
<xsl:call-template name="hour"/>
</th>
</tr>
</table>
</xsl:template>
<xsl:template name="tvchan">
<xsl:for-each select="/TVGuide/Channel">
<th>
<td>
<xsl:value-of select ="Name"/>
</td>
</th>
</xsl:for-each>
</xsl:template>
<xsl:template name="hour">
<xsl:for-each select="/TVGuide/Channel/Program[not(./Start=following::Start)]">
<xsl:sort select="Start"/>
<xsl:variable name="zman" select ="Start"/>
<tr>
<td>
<xsl:value-of select="Start"/>
</td>
<xsl:for-each select="/TVGuide/Channel/Program[Start=$zman]">
<xsl:variable name="name1">
<xsl:choose>
<xsl:when test="Title!=''">
<xsl:value-of select="Title"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="Series"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<td>
<xsl:value-of select="$name1"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
结果应该显示一个包含所有程序和时间的表格。
http://dl.dropbox.com/u/99771726/table.png
非常感谢你的帮助。