title: How to generate XML for Menu using Dataset and display menu and menu items
body: <p>I need to generate a menu based on the values in the table/ dataset. The table contains data similar to the Image data below. The main menu contains 4 values, Products, Applications, Documents, Support. Each menu has its menu items. </p>
  
  <p><img src="https://i.stack.imgur.com/lrr0Q.jpg" alt="Menu and MenuItems"></p>
  
  <p><img src="https://i.stack.imgur.com/4tTsw.png" alt="enter image description here"></p>
  
  <p>Below is the sitemaster code for the master page:</p>
  
  <pre><code>&lt;asp:Menu ID="Menu1" runat="server" DataSourceID="XmlDataSource1" BackColor="#0072c5"
   CssClass="Menu" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="12px"
   ForeColor="#F7F6F3" Width="100%" StaticSubMenuIndent="10px" Orientation="Horizontal"
   StaticDisplayLevels="2"&gt;
   &lt;DataBindings&gt;
      &lt;asp:MenuItemBinding DataMember="MenuItem" NavigateUrlField="NavigateUrl"  TextField="Text" ToolTipField="ToolTip" /&gt;
   &lt;/DataBindings&gt;
  &lt;/asp:Menu&gt;
   &lt;asp:XmlDataSource ID="XmlDataSource1" TransformFile="~/Default2.xslt" XPath="MenuItems/MenuItem"runat="server"&gt;&lt;/asp:XmlDataSource&gt;
  </code></pre>
  
  <p>I generated XML as below.</p>
  
  <pre><code>&lt;Menus ProductName="Acapella Admin"&gt;
  
      &lt;Menu MenuID="1" Text="Products"&gt;
      &lt;MenuItem MenuID="1" Text="ProductInfo"  URL="ProductInfo.aspx"/&gt;
      &lt;MenuItem MenuID="2" Text="Product Features"  URL="ProductFeatures.aspx"/&gt;
      &lt;MenuItem MenuID="3" Text="Products Details" URL="ProductDetails.aspx" /&gt;
      &lt;/Menu&gt;
  
     &lt;Menu MenuID="1" Text="Applications"&gt;
      &lt;MenuItem MenuID="1" Text="MobileApps"  URL="MobileApps.aspx"/&gt;
      &lt;MenuItem MenuID="2" Text="Web Applications"  URL="WebApplications.aspx"/&gt;
      &lt;MenuItem MenuID="3" Text="Portal" URL="Portal.aspx" /&gt;
      &lt;/Menu&gt;
  
      &lt;Menu MenuID="2" Text="Document"&gt;
      &lt;MenuItem MenuID="4" Text="Tutorial" URL="Tutorial.aspx" /&gt;
      &lt;/Menu&gt;
  
      &lt;Menu MenuID="4" Text="Support"&gt;
      &lt;MenuItem MenuID="5" Text="FAQs" URL="FAQs.aspx"  /&gt;
      &lt;MenuItem MenuID="6" Text="Contact us" URL="ContactUS.aspx" /&gt;
       &lt;/Menu&gt;
  
  &lt;/Menus&gt; 
  </code></pre>
  
  <p>And my XSLT stylesheet:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" indent="yes" encoding="utf-8"/&gt;
  
  
    &lt;!-- Replace root node name Menus with MenuItems
         and call MenuListing for its children--&gt;
    &lt;xsl:template match="/Menus"&gt;
      &lt;MenuItems&gt;
        &lt;xsl:call-template name="MenuListing" /&gt;
      &lt;/MenuItems&gt;
    &lt;/xsl:template&gt;
  
    &lt;!-- Allow for recursive child nodeprocessing --&gt;
    &lt;xsl:template name="MenuListing"&gt;
      &lt;xsl:apply-templates select="Menu" /&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="Menu"&gt;
      &lt;MenuItem&gt;
        &lt;!-- Convert Menu child elements to MenuItem attributes --&gt;
        &lt;xsl:attribute name="Text"&gt;
          &lt;xsl:value-of select="Text"/&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:attribute name="ToolTip"&gt;
          &lt;xsl:value-of select="Description"/&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:attribute name="NavigateUrl"&gt;
          &lt;xsl:text&gt;?Sel=&lt;/xsl:text&gt;
          &lt;xsl:value-of select="Text"/&gt;
        &lt;/xsl:attribute&gt;
  
        &lt;!-- Recursively call MenuListing forchild menu nodes --&gt;
        &lt;xsl:if test="count(Menu) &gt;0"&gt;
          &lt;xsl:call-template name="MenuListing" /&gt;
        &lt;/xsl:if&gt;
      &lt;/MenuItem&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Help me in generating XML And binding it to the menu with XmlDataSource.</p>