<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>XML and XmlDataSource Control</title><link>http://forums.asp.net/43.aspx</link><description>All about XML, XSLT, and the XmlDataSource control.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Shouldn't this be simple?</title><link>http://forums.asp.net/thread/978227.aspx</link><pubDate>Tue, 05 Jul 2005 17:03:47 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:978227</guid><dc:creator>KraGiE</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/978227.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=978227</wfw:commentRss><description>If the output is complex or will frequently change, I'd go with XSL,
but to simply output the contents, I'd probably just loop the nodes,
and output directly through code.&lt;br&gt;
&lt;br&gt;
No reason to have double IO reads.&amp;nbsp; :)&lt;br&gt;
&lt;br&gt;</description></item><item><title>Re: Shouldn't this be simple?</title><link>http://forums.asp.net/thread/977713.aspx</link><pubDate>Tue, 05 Jul 2005 11:07:21 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:977713</guid><dc:creator>JasonFollas</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/977713.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=977713</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Unfortunately, ASP.NET is not particularly my forte, so I can't just simply tell you how to do it using controls.&amp;nbsp; However, I have worked with XSLT quite a bit in the past, and that sounds perfect for this scenario.&lt;BR&gt;&lt;BR&gt;XSLT is a transformation technology.&amp;nbsp; It's purpose is to transform your original tree into another tree, but the output is text, and thus, does not necessarily need to be well-formed XML.&amp;nbsp; So, my code's goal is to transform your XML into an HTML snippet which can then be inserted into your web page, either via the Response stream, or some other method.&lt;BR&gt;&lt;BR&gt;First, the .NET code:&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;xmlDoc.Load(@"c:\meals.xml");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;xslt.Load(@"c:\meals.xsl");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Xml.XmlReader reader = xslt.Transform(xmlDoc, null, new System.Xml.XmlUrlResolver());&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.MoveToContent();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string results = reader.ReadInnerXml();&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;Next, is the contents of the "meals.xsl" file.&amp;nbsp; I use templates here, which allows for the maximum flexibility in customizing how each individual node in your XML tree is rendered.&amp;nbsp; Note that "&amp;amp;nbsp;" is not an XML entity, so you need to use the character code equivilent of the non-breaking space, "&amp;amp;#160;".&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;xsl:stylesheet&amp;nbsp;&amp;nbsp; version="1.0" &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:xsl="&lt;/FONT&gt;&lt;A href="http://www.w3.org/1999/XSL/Transform"&gt;&lt;FONT face="Courier New" size=2&gt;http://www.w3.org/1999/XSL/Transform&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New" size=2&gt;"&amp;gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;xsl:template match="/"&amp;gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:apply-templates select="meals" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;lt;/xsl:template&amp;gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;xsl:template match="meals"&amp;gt;&lt;BR&gt;&amp;lt;meals&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:apply-templates select="meal[@id='Breakfast']" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:apply-templates select="meal[@id='Lunch']" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:apply-templates select="meal[@id='Dinner']" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:apply-templates select="meal[@id='Snacks']" /&amp;gt;&lt;BR&gt;&amp;lt;/meals&amp;gt;&lt;BR&gt;&amp;lt;/xsl:template&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;xsl:template match="meal"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select="@id" /&amp;gt; (&amp;lt;xsl:value-of select="calories" /&amp;gt; Calories) &amp;lt;br/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;amp;#160;&amp;amp;#160;&amp;amp;#160; &amp;lt;xsl:apply-templates select="foods" /&amp;gt; &amp;lt;br /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;br /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;lt;/xsl:template&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;xsl:template match="foods"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:apply-templates select="food" /&amp;gt;&lt;BR&gt;&amp;lt;/xsl:template&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;xsl:template match="food"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select="." /&amp;gt;&amp;lt;xsl:if test="position() != last()"&amp;gt;, &amp;lt;/xsl:if&amp;gt;&lt;BR&gt;&amp;lt;/xsl:template&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;The output of the transformation is the following (not exactly intended for human consumption, but not too bad):&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;meals&amp;gt;&lt;BR&gt;Breakfast (215 Calories) &amp;lt;br /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Corn Flakes Cereal, Frozen Sweet Rasberries, Soy Milk&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Lunch (342 Calories) &amp;lt;br /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Hard Roll, Orange, Butternut Squash with Ginger&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Dinner (538 Calories) &amp;lt;br /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Cooked Couscous, Raw Broccoli, Curried Chicken with Almonds&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Snacks (233 Calories) &amp;lt;br /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Orange, Sunflower seeds&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;BR&gt;&amp;lt;/meals&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;From this, we grab the contents of the &amp;lt;meals&amp;gt; node, which is then inserted into your rendering web page.&amp;nbsp; &lt;BR&gt;&lt;BR&gt;The resulting rendered HTML looks like:&lt;BR&gt;&lt;/FONT&gt;___________________________________________________________________________&lt;BR&gt;Breakfast (215 Calories) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Corn Flakes Cereal, Frozen Sweet Rasberries, Soy Milk&lt;/P&gt;
&lt;P&gt;Lunch (342 Calories) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hard Roll, Orange, Butternut Squash with Ginger&lt;/P&gt;
&lt;P&gt;Dinner (538 Calories) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cooked Couscous, Raw Broccoli, Curried Chicken with Almonds&lt;/P&gt;
&lt;P&gt;Snacks (233 Calories) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Orange, Sunflower seeds&lt;BR&gt;___________________________________________________________________________&lt;BR&gt;&lt;/P&gt;</description></item><item><title>Shouldn't this be simple?</title><link>http://forums.asp.net/thread/977351.aspx</link><pubDate>Mon, 04 Jul 2005 21:42:25 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:977351</guid><dc:creator>mdleichty</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/977351.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=977351</wfw:commentRss><description>&lt;P&gt;I'm just starting to delve into both ASP.NET and XML.&amp;nbsp; My XML file has this:&lt;BR&gt;&lt;BR&gt;&amp;lt;?xml version="1.0" encoding="iso-8859-1"?&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;lt;meals&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;lt;meal id="Breakfast"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Corn Flakes Cereal&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Frozen Sweet Rasberries&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Soy Milk&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;calories&amp;gt;215&amp;lt;/calories&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/meal&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;lt;meal id="Lunch"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Hard Roll&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Orange&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Butternut Squash with Ginger&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;calories&amp;gt;342&amp;lt;/calories&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/meal&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;lt;meal id="Dinner"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Cooked Couscous&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Raw Broccoli&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Curried Chicken with Almonds&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;calories&amp;gt;538&amp;lt;/calories&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/meal&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;lt;meal id="Snacks"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Orange&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;food&amp;gt;Sunflower seeds&amp;lt;/food&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/foods&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;calories&amp;gt;233&amp;lt;/calories&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/meal&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;lt;/meals&amp;gt;&lt;BR&gt;&lt;BR&gt;... And I want my ASP.NET page to output this&lt;BR&gt;&lt;BR&gt;Breakfast (215 calories)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Corn Flakes Cereal,&amp;nbsp;Frozen Sweet Rasberries, Soy Milk&lt;BR&gt;&lt;BR&gt;Lunch (342 calories)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Hard Roll,&amp;nbsp;Orange, Butternut Squash with Ginger&lt;BR&gt;&lt;BR&gt;etc.&lt;BR&gt;&lt;BR&gt;Obviously, there will not always be three items (or any items), or there may not be snacks on&amp;nbsp;a particular day.&amp;nbsp; I'm not sure how to use the datalist / datagrid / repeater to achieve this simply.&amp;nbsp; &lt;/P&gt;</description></item></channel></rss>