Link to home
Start Free TrialLog in
Avatar of atljarman
atljarman

asked on

ASP .NET Replace site.master script and Menu XQuery or XLST?

I am creating a Content Management System that I uses a site.master.  In the current site.master, I use VB script to assign CSS values for the Page Title and H1 tags.  I also use VB Script to create class tags for the menu to make it dymanic drop down menu.  For example, when a user clicks on the main or sub menu item, the sub-bullets remain listed as a drop down.  When the click another main menu item, those previously displayed are hidded (but are still included in the page).  I created an xml file and management page that allows me to add/edit rows of the XML data that correspond with the information needed to develop the Title/H1 script, menu script, and then the menu itself in the file.

I then created a page to replace the site.master using a .writeline() procedure, but am having trouble re-creating the scripts on the file.

I think I would need to do some type of loop combined with IF/Then statements.  I would need to know the following:

1. Count the total number of rows in the same group.
2. Determine if the current row is a) the only one in the group (the main menu item with no submenu items), b) the first one in a group (the main menu item that has sub menu items), c) the second one in a group (the first sub-menu item), d) the last one in a group, any other one in a group (other sub menu item)
3. Write the menu items and script in the page.

I've done this using an VBA and a sheet in Excel (using formulas in hidden rows to assign values in #2 above).

Is there a way to do this with XQuery or XSTL to write this information into the site master?  Or is there a better way to do this?  I'm really at a loss here, and not sure that it is even possible.
'Script in the VBA, will need to be appended so that more menu items could be added.
   
            StrWer.WriteLine("      Function CurrTitle() As String")
            StrWer.WriteLine("      If Request.Path.Contains(" & """" & "default.aspx" & """" & ") Then")
            StrWer.WriteLine("      Return " & """" & " - Welcome!" & """")

	'Menu items code here.

            StrWer.WriteLine("      Else")
            StrWer.WriteLine("      Return " & """" & """")
            StrWer.WriteLine("      End If")
            StrWer.WriteLine("      End Function")

Results in:

'Title Tag VB Script code
      Function CurrTitle() As String 
        If Request.Path.Contains("default.aspx") Then
            Return "- Welcome!"

	'Menu items code here <needed>.

        Else
            Return ""
        End If
    End Function


'The script needed also needs to be create the two example below, the first one is a single menu item with no submenu items with the second having sub menu items.

    Function CurrMenu6() As String
        If Request.Path.Contains("career_development.aspx") Then
            Return "id='selmenu'"
        Else : Return ""
        End If
    End Function
      
    Function CurrMenu7() As String
        If Request.Path.Contains("links.aspx") _
      Or Request.Path.Contains("links_usphs.aspx") _
       Or Request.Path.Contains("links_colleges.aspx") Then
            Return "id='selmenu'"
        Else : Return ""
        End If
    End Function


    'Create the code that displays sub-menu items
      
    Function SubMenu7() As String
        If Request.Path.Contains("links.aspx") _
       Or Request.Path.Contains("links_usphs.aspx") _
      Or Request.Path.Contains("links_colleges.aspx") Then
            Return "class='displayme'"
        Else
            Return "class='hideme'"
        End If
    End Function

<ul id='main-nav' title='Navigation Bar'>
      <li><a href='default.aspx' title='HOME' <%= CurrMenu1 %>  tabindex='51'>HOME</a></li>
      <li><a href='career_development.aspx' title='CAREER DEVELOPMENT' <%= CurrMenu6 %>  tabindex='57'>CAREER DEVELOPMENT</a></li>
      <li><a href='links.aspx' title='LINKS' <%= CurrMenu7 %>  tabindex='58'>LINKS</a>
      <ul <%= SubMenu7 %>><li><a href='links_usphs.aspx' title='USPHS Links' tabindex='59'>USPHS Links</a></li>
      <li><a href='links_colleges.aspx' title='Other Links' tabindex='60'>Other Links</a></li></ul></li>
</ul>

Open in new window

Avatar of atljarman
atljarman

ASKER

Here is one example, but I am not able to get the example to work when I store the file referenced under C:\xml\

http://en.wikibooks.org/wiki/XQuery/Sitemap_for_Content_Management_System
This looks like it could be a promising start, but I am not sure how to pull it into the page (e.g., namespaces, sub)
XmlDocument doc = new XmlDocument();
doc.Load("filename.xml");

StringBuilder sb = new StringBuilder();

sb.AppendLine("<ul>");
foreach (XmlNode item in doc.GetElementsByTagName("Parent"))
{
sb.Append("<li>");
sb.Append("<a href=\"" 
+ item.Attributes["href"].Value 
+ "\">" 
+ item.Attributes["text"].Value + "</a>");
if (item.HasChildNodes)
{
    sb.AppendLine("\n<ul>");
    foreach (XmlNode c in item.ChildNodes)
    {
        sb.AppendLine("<li><a href=\""
+ c.Attributes["href"].Value 
+ "\">" 
+ c.Attributes["text"].Value 
+ "</a></li>");
    }
    sb.AppendLine("</ul>");
}
sb.AppendLine("</li>");
}
sb.AppendLine("</ul>");

Response.Write(sb.ToString());

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of atljarman
atljarman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See the above posted link for the solution to the menu display.