capturing a sequence within a sequence - xquery

Say I have a sequence of items,
<items>
<item>B</item>
<item>D</item>
<item>A</item>
<item>B</item>
<item>C</item>
</items>
and I want to capture all sequences of A- and B-items
<items>
<item>B</item>
<item>D</item>
<hit>
<item>A</item>
<item>B</item>
</hit>
<item>C</item>
</items>
Can this be done with XQuery? When iterating, the context item is singular.
I can get
<items>
<item>B</item>
<item>D</item>
<hit-start><item>A</item></hit-start>
<hit-end><item>B</item></hit-end>
<item>C</item>
</items>
but that does not help, nor does
<items>
<item>B</item>
<item>D</item>
<hit-start/>
<item>A</item>
<item>B</item>
<hit-end/>
<item>C</item>
</items>

You can "look around" using preceding-sibling and following sibling.
<items>{
for $item in $xml/items/item
return
if ($item = "A" and $item/following-sibling::item[1] = "B")
then (
<hit-start/>,
<item>A</item>,
<item>B</item>,
<hit-end/>
)
else
$item[not(preceding-sibling::item[1] = "A")]
}</items>

Related

OData model binding in XML with $expand

I'm trying to bind data from the back end to XML view.
Here is my List control definition:
<List items="{path : '/ZZMM_VDB_DETAILSet', parameters:{expand: 'ZZMM_VDB_DETAIL_TO_MATKLSSet'}}">
<items>
<CustomListItem>
<content>
<List items="{path: 'ZZMM_VDB_DETAIL_TO_MATKLSSet'}">
<items>
<ObjectListItem title="Matkl : {Matkl}"></ObjectListItem>
</items>
</List>
</content>
</CustomListItem>
</items>
</List>
I want to display the data of the expanded entity set which consists of 16 objects.
What I get displayed is 15 times object before the last one (array element number 14) and the last row is the data of the last array element (number 15).
What do I miss here?

Passing a value from menu items

I would like to pass a value from menu item to the respected navigation page.
<asp:menu id="myMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Horizontal"
dynamichorizontaloffset="10"
onmenuitemclick="myMenu_MenuItemClick"
target="_blank"
runat="server" ForeColor="White" >
<items>
<asp:menuitem
text="Home"
tooltip="Home">
<asp:menuitem
text="Music"
tooltip="Music">
<asp:menuitem
text="Classical"
tooltip="Classical"/>
<asp:menuitem
text="Rock"
tooltip="Rock"/>
<asp:menuitem
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem
text="Movies"
tooltip="Movies">
<asp:menuitem
text="Action"
tooltip="Action"/>
<asp:menuitem
text="Drama"
tooltip="Drama"/>
<asp:menuitem
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
The code to pass the MenuItem Text is as below:
protected void myMenu_MenuItemClick(object sender, EventArgs e)
{
Session["1"] = (sender as MenuItem).Text;
Response.Redirect("~/CategorySearch.aspx?Category=" + Session["1"].ToString());
}
I get a NullReferenceException which is quite interesting because I am just passing the text of the MenuItem.Why is that?
If you have an event handler attached to your menu (or menu item), you can easily cast the sender as a MenuItem like so:
Webforms:
<asp:Menu runat="server" ID="mymenu" OnMenuItemClick="mymenu_MenuItemClick">
<Items>
<asp:MenuItem Text="Home" />
<asp:MenuItem Text="Contact" />
<asp:MenuItem Text="About Us" />
</Items>
</asp:Menu>
Code Behind:
protected void mymenu_MenuItemClick(object sender, MenuEventArgs e)
{
// this is the menu itself, you can iterate the Items collection if you need.
var menu = (sender as Menu);
foreach (MenuItem item in menu.Items)
{
System.Diagnostics.Debug.Print(item.Text);
}
// this is the MenuItem object that was clicked
var clickedMenuItem = e.Item;
// store text value in your session
Session["1"] = e.Item.Text;
// redirect
Response.Redirect("~/CategorySearch.aspx?Category=" + e.Item.Text);
}

how to add menu at front

i am using menu control in asp.net and i am having already 4 menu items, but i want to add 3 more menu items at front.how to achieve this ?
<asp:Menu ID="MainMenu" runat="server" Orientation="Horizontal"
CssClass="styleMenu" Width="100%" >
<Items>
<asp:MenuItem Text="Approval" Value="3"></asp:MenuItem>
<asp:MenuItem Text="Search" Value="4"></asp:MenuItem>
<asp:MenuItem Text="Admin" Value="5"></asp:MenuItem>
<asp:MenuItem Text="Report" Value="6"></asp:MenuItem>
</Items>
</asp:Menu>
I am writing the code for adding dynamic menu items as
MenuItem mnuTest = new MenuItem();
mnuTest.NavigateUrl = "";
mnuTest.Text = "Test";
MainMenu.Items.Add(mnuTest);
but the latest menu is adding at last , how to add at front as 1st menu item
MainMenu.Items.AddAt(0, mnuTest);

.NET 4.5: ASP Menu Item value displaying as a link?

In my code below the asp menu item value property is actually rendering as link text!
<asp:Menu ID="menuTop" runat="server" EnableViewState="true" Orientation="Horizontal" StaticSelectedStyle-CssClass="menuselected" SkipLinkText="">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" ImageUrl="~/images/Menu_Home.jpg" Value="Home" />
<asp:MenuItem NavigateUrl="~/Contact.aspx" ImageUrl="~/images/Menu_Contact.jpg" Value="Contact"/>
</Items>
</asp:Menu>
According to the MSDN reference located at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.value.aspx
The Value property is used to supplement the Text property by storing
any additional data associated with the menu item. This value is not
displayed in the control and is commonly used to store data for
handling postback events.
I need it to store values, why is it displaying as link text?
Try this code.
<asp:Menu ID="menuTop" runat="server" EnableViewState="true" Orientation="Horizontal" StaticSelectedStyle-CssClass="menuselected" SkipLinkText="">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" ImageUrl="~/images/Menu_Home.jpg" Value="Home" Text="" />
<asp:MenuItem NavigateUrl="~/Contact.aspx" ImageUrl="~/images/Menu_Contact.jpg" Value="Contact" Text=""/>
</Items>
</asp:Menu>
Nevermind, I figured it out. Looks like you need to set the Text value to "" and that prevents the value from displaying as text.

How to set items spacing in a horizontal menu?

Horizontal menu items:
<asp:MenuItem Text="Registration" Value="Registration"></asp:MenuItem>
<asp:MenuItem Text="Log In" Value="Log In"></asp:MenuItem>
<asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
Problem: space between items is the same as the space between words in an item (Log In, About Us).
I'm looking for a property named "itemspace" or something like that, but, it seems there is no such one.
Or, maybe, there is?
<staticmenuitemstyle horizontalpadding="10"/>
Alternatively, I have used this approach:
<StaticMenuItemStyle ItemSpacing="10px"/>
Add border width as an alternative
<staticmenuitemstyle BorderWidth="20px" BackColor="Green" BorderColor="#ededed" forecolor="Black"/>

Resources