我正在做一个使用 XML 文件的博客。我想用 ListView 显示所选帖子的评论。这是我的 XML 文件:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<NewDataSet>
<Toy>
<ID>1</ID>
<Type>Despicable Me</Type>
<Character>Agnes Gru</Character>
<Description>Agnes, like her sisters, wished to be adopted by someone who cared about her.
At first, Agnes is only one out of the three sisters to be excited to be adopted by Gru.
She happily hugs his leg and plays games with him, whereas her sisters are gawping at
Gru, their dream of the 'perfect parents' in tatters.
She is unaware of Gru's own dislike of the whole adoption, her innocence prevailing.
She is a very naive and innocent child, which is why Margo is so protective of her.
She thinks Gru's dog is cute and chases after him, despite some protest from Margo.
</Description>
<Picture>agnes.jpg</Picture>
<Comments>
<Comment>
It's a very cute little girl!
</Comment>
<Comment>
It's a very cute little girl!
</Comment>
</Comments>
</Toy>
</NewDataSet>
这是我的 xsl 文件:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="NewDataSet">
<NewDataSet>
<xsl:apply-templates/>
</NewDataSet>
</xsl:template>
<xsl:template match="Toy/Comments">
<Toy>
<Comments>
<xsl:for-each select="*">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:for-each>
</Comments>
</Toy>
</xsl:template>
</xsl:stylesheet>
这是我背后的代码:(我已经成功通过了会话)
protected void Page_Load(object sender, EventArgs e)
{
String ID = Session["ID"].ToString();
XmlDataSource2.XPath = String.Format("/NewDataSet/Toy[@ID='{0}']/Comments",ID);
}
我认为我的代码有问题。谁能帮助我?谢谢你。