1
我想使用XSLT样式表来设置XML数据的样式。在我的XML文件“V”和“H”中,我有两个团队访问和回家。我想在两个单独的表格中显示他们的统计数据。我只是不确定如何告诉XSLT,我只想要特定团队的属性。我想能够说xsl:value-of select =“team”,其中vh attribute =“V”pull出ID,姓名,录音等
XML的这些值:如何显示特定节点的XSLT中的属性?
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
<bbgame source="STAT CREW Basketball" version="4.15.03" generated="12/17/2013">
<team vh="V" id="MSU" name="MISSOURI STATE" record="8-2">
<linescore line="24,36" score="60">
<lineprd prd="1" score="24"></lineprd>
<lineprd prd="2" score="36"></lineprd>
</linescore>
</team>
<team vh="H" id="LOU" name="LOUISVILLE" record="10-1">
<linescore line="47,43" score="90">
<lineprd prd="1" score="47"></lineprd>
<lineprd prd="2" score="43"></lineprd>
</linescore>
</team>
</bbgame>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="bbgame">
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/
</head>
<body>
<h1>Official Basketball Box Score -- Game Totals</h1>
<table>
<tr>
<td><xsl:value-of select="venue/@visname"/> vs. </td>
<td><xsl:value-of select="venue/@homename"/></td>
<td><xsl:value-of select="venue/@date"/></td>
<td><xsl:value-of select="venue/@time"/></td>
<td><xsl:value-of select="venue/@location"/></td>
</tr>
</table>
<table>
<tr>
<td>
<xsl:value-of select="team/@id"/></td>
<td> <xsl:value-of select="team/linescore/@score"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
编辑:
<table>
<xsl:if test="team[@vh="V"]">
<tr>
<td> <xsl:value-of select="team/@id"/></td>
<td> <xsl:value-of select="team/linescore/@score"/></td>
</tr>
</xsl:if>
</table>
在XSLT的底部,我有xsl:value-of select =“team/@ id”。我需要在团队之前放置一个? –
/不需要。关键是[@vh =“...”]。 –
好的。我道歉,我应该更具体。我想创建一个HTML表格,说明团队vh = V,然后输出Name,Record,Score的特定值。 –