Choose the comments element for the selected node in xml
I am doing a blog which using the XML file. I want to display the comments
for selected Post with ListView. Here is my XML File:
<?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>
Here is my xsl file:
<?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>
Here is my code behind: (I had successfully passed the Session)
protected void Page_Load(object sender, EventArgs e)
{
String ID = Session["ID"].ToString();
XmlDataSource2.XPath =
String.Format("/NewDataSet/Toy[@ID='{0}']/Comments",ID);
}
I think something wrong with my code behind. Can anyone please assist me?
Thank You.
No comments:
Post a Comment