末世男的异世屯粮生活:XML为什么显示效果不对?

来源:百度文库 编辑:高考问答 时间:2024/05/08 11:56:36
XML代码如下:
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="vote.xsl"?>
<VoteGroup Title="本站调查第一期">
<OptionGroup Title="你的性别是?" Type="RadioButton">
<OptionItem Title = "男" Count="0"></OptionItem>
<OptionItem Title = "女" Count="0"></OptionItem>
<OptionItem Title = "保密" Count="0"></OptionItem>
</OptionGroup>
<OptionGroup Title="你是通过什么了解到本站的?" Type="RadioButton">
<OptionItem Title = "朋友介绍" Count="0"></OptionItem>
<OptionItem Title = "网站广告" Count="0"></OptionItem>
<OptionItem Title = "搜索引擎" Count="0"></OptionItem>
<OptionItem Title = "友情链接" Count="0"></OptionItem>
</OptionGroup>
</VoteGroup>

XSL如下:
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="/VoteGroup/@Title"/></title>
</head>
<body>
<xsl:apply-templates select="VoteGroup"/>
</body>
</html>
</xsl:template>

<xsl:template match="VoteGroup">
<font color="#FF0000"><xsl:value-of select="@Title"/></font>
<xsl:for-each select="OptionGroup">
<xsl:apply-templates select="OptionGroup"/>
</xsl:for-each>
</xsl:template>

<xsl:template match="OptionGroup">
<br/>
<font color="#333333"><xsl:value-of select="@Title"/></font>
<xsl:for-each select="OptionItem">
<xsl:apply-templates select="OptionItem"/>
</xsl:for-each>
</xsl:template>

<xsl:template match="OptionItem">
<br/>
<xsl:value-of select="@Title"/>
</xsl:template>

</xsl:stylesheet>

我想把选项列出来,可是显示不出来,..这个怎么改?

然后我想根据类型添加单选或者复选的HTML标签,这个怎么做?

试试下面这个xsl:

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="/VoteGroup/@Title"/></title>
</head>
<body>
<xsl:apply-templates select="VoteGroup"/>
</body>
</html>
</xsl:template>

<xsl:template match="VoteGroup">
<font color="#FF0000"><xsl:value-of select="@Title"/></font>
<xsl:apply-templates select="OptionGroup"/>
</xsl:template>

<xsl:template match="OptionGroup">
<br/>
<font color="#333333"><xsl:value-of select="@Title"/></font>
<xsl:apply-templates select="OptionItem"/>
</xsl:template>

<xsl:template match="OptionGroup[@Type='RadioButton']/OptionItem">
<br/>
<xsl:element name="input">
<xsl:attribute name="type">radio</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="@Title" /></xsl:attribute>
</xsl:element>
<xsl:value-of select="@Title"/>
</xsl:template>

<xsl:template match="OptionGroup[@Type='CheckBox']/OptionItem">
<br/>
<xsl:element name="input">
<xsl:attribute name="type">checkbox</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="@Title" /></xsl:attribute>
</xsl:element>
<xsl:value-of select="@Title"/>
</xsl:template>

</xsl:stylesheet>