Selecting sibling nodes using position() - dom

I've got a trouble selecting divs following specific title in code:
<div>
<h2>Section 1</h2>
<div>Item 1</div>
<div>Item 2</div>
<h2>Section 2</h2>
<div>Item 3</div>
<div>Item 4</div>
<div>Item 5</div>
</div>
I was trying to get the nodes using preceding-sibling somehow like this:
//div/div[preceding-sibling::h2[1][position()=1]]
I need all divs which have the NEAREST preceding h2 sibling on position 1, but I'm still getting all 5 items.
Can you tell me what am I doing wrong?
Example output with position 1 (section 1):
<div>Item 1</div>
<div>Item 2</div>
Example output with position 2 (section 2):
<div>Item 3</div>
<div>Item 4</div>
<div>Item 5</div>

This can be a tricky thing to do, but one approach you can use is count():
//div/div[count(preceding-sibling::h2) = 1]
The reason your attempt with position() didn't work is that position() is evaluated relative to the current selection. With preceding-sibling::h2[1][position()=1], you are selecting the nearest h2 and then selecting the first node in that set.

Related

How can I fuse columns vertically together like with rowspan in HTML in an ion-grid table?

Ok here I am, asking yet another question that's probably already been answered but I couldn't find the answer in the ionic-documentations so here goes nothing:
I got an Ion-grid with 3 columns and around 20 Rows and I would like to fuse the 3rd column of the last 4 rows together just like you can do in HTML with rowspan.
I know that you can combine them horizontally by adding size="..." to the ion-col, but I didn't see any option to do it vertically.
The grid looks basically like this:
<ion-grid>
<ion-row>
<ion-col>Sum random text</ion-col>
<ion-col>Sum random number</ion-col>
<ion-col>Sum random radio-button</ion-col>
</ion-row>
... //Just the same thing a few times
//the last 4 rows belong together and therefore I only want
//One button for all 4 of them -> the 3rd column of the last 4 rows
//should be one single field
</ion-grid>
So doing some research it seems that this is the way you could do it:
<ion-grid>
<ion-row>
<ion-col size="3">Sum random text</ion-col>
<ion-col size="3">Sum random number</ion-col>
<ion-col size="3">Sum random radio-button</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-row size="6">
<ion-col>This is cell row 1</ion-col>
</ion-row>
<ion-row size="6">
<ion-col>This is cell row 2</ion-col>
</ion-row>
<ion-row size="6">
<ion-col>This is cell row 2</ion-col>
</ion-row>
</ion-col>
<ion-col>
<ion-col>This cell is the 3 rows "merged"<ion-col>
</ion-col>
</ion-row>
</ion-grid>
This is just written off the top of my head so it will probably need some tweaking.

Generate different images by languages in typoscript

I want to generate different images depending on the languages with TypoScript.
<img src="/specilized-nl.png" alt="logo">
<img src="/specilized-en.png" alt="logo">
<img src="/specilized-de.png" alt="logo">
So depending on the selected languages the correct image is shown by using a different image name. How could this be done?
use conditions on language parameter (most probably L)...
lib.myImage = <img src="/specilized-nl.png" alt="logo">
[globalVar = GP:L = 1]
lib.myImage = <img src="/specilized-en.png" alt="logo">
[global]
[globalVar = GP:L = 2]
lib.myImage = <img src="/specilized-de.png" alt="logo">
[global]
Of course I assume in that sample, the NL is default, EN has uid 1, and DE has uid 2, fix it to reflect your real situation.

Creating Lift nested Submenus in different div

I'm trying to build a nested menu structure, but the submenus should appear in a different element on the page.
Grouping and hiding the submenus will make them appear always, not just after activating the parent menu.
Menu.i("Startseite") / "index" >> Hidden >> LocGroup("servicenav"),
Menu.i("Impressum") / "about"/"index" >> Hidden >> LocGroup("servicenav"),
Menu.i("menu_1") / "100_menu1" submenus(
Menu.i("menu_1a") / "100_menu1a" >> Hidden >> LocGroup("sidenavbar"),
Menu.i("menu_1b") / "200_menu1b" >> Hidden >> LocGroup("sidenavbar"),
Menu.i("menu_1c") / "300_menu1c" >> Hidden >> LocGroup("sidenavbar")
),
Menu.i("menu_2") / "400_menu2" submenus(
Menu.i("menu_2a") / "400_menu2a" >> Hidden >> LocGroup("sidenavbar"),
Menu.i("menu_2b") / "500_menu2b" >> Hidden >> LocGroup("sidenavbar")
)
)
And the html part:
<ul id="mainnav">
<lift:Menu.builder li_item:class="open" li_path:class="open">
Upper Navigation Panel for primary Menu
</lift:Menu.builder>
</ul>
<ul id="nav">
<lift:Menu.group group="sidenavbar" a:class="firstChild">
Side-Navigation panel for submenus
<li><menu:bind /></li>
</lift:Menu.group>
</ul>
Has anyone a good idea?
Thanks in advance
You didn't specify the "group" in the first part of the HTML. Maybe this would help ?
I understood you incorrectly the first time.
Would level solve your problem?
level: What level of the entire selected menu tree to show. Counting begins at zero, for the top level. Consider a top level menu with ‘item1’, ‘item2’, and ‘item3’ and supposed ‘item1’ has a submenu with items ‘item1a’ and ‘item1b’. Level 0 will show the top level plus the submenus (see next option). If item2 or item3 is selected level 1 will show nothing, while if one of the item1 variants is selected the item1a and item1b entries will be displayed.
https://www.assembla.com/wiki/show/liftweb/SiteMap#using_sitemap_in_templates
Ok, I created a workaround by grouping the top-menu level and let the submenu appear in the main-sitemap. With this, the level-parameter can be applied and therefore only the active submenus appear in the div.
Menu.i("Startseite") / "index" >> Hidden >> LocGroup("servicenav"),
Menu.i("Impressum") / "about"/"index" >> Hidden >> LocGroup("servicenav"),
Menu.i("menu_1") / "100_menu1" >> LocGroup("mainnavbar") submenus(
Menu.i("menu_1a") / "100_menu1a",
Menu.i("menu_1b") / "200_menu1b",
Menu.i("menu_1c") / "300_menu1c"
),
Menu.i("menu_2") / "400_menu2" >> LocGroup("mainnavbar") submenus(
Menu.i("menu_2a") / "400_menu2a",
Menu.i("menu_2b") / "500_menu2b"
)
And the HTML:
<ul id="mainnav">
<lift:Menu.group group="mainnavbar" level="1">
<li><menu:bind />
</li>
</lift:Menu.group>
</ul>
<div id="navblock">
<ul id="nav">
<lift:Menu.builder level="1" li_item:class="opfirstChildOpenen" li_path:class="firstChildOpen">
Side-Navigation panel for submenus
</lift:Menu.builder>
</ul>
</div>
So, finally got a solution.
I simlpy added two Sitemaps. The first with with level="0" and expand="false", the second with level="1". However if you click in the second menu, the first will expand regardless of the expand parameter. So I set the in the stylesheet the width and heigth for the following in the first menu to 0.
Not clean, but it works...
<ul id="mainnav">
<lift:Menu.builder li_path:class="open" level="0" expand="false">
Top Menu
</lift:Menu.builder>
</ul>
<ul id="nav">
<lift:Menu.builder level="1" li_item:class="current" li_path:class="open">
Side-menu
</lift:Menu.builder>
</ul>
ul#mainnav li ul li{
height: 0;
width: 0;
}

Opacity toggle three (or more) DIV

<div id="rotator">
<p id="1">Some Text 1</p>
<p id="1">Some Text 2</p>
<p id="1">Some Text 3</p>
</div>
They are presented in a row. All I want is automatically cycle the three text by toggling opacity, ie. at first text 1 is opacity 1, and test 2 and 3 are opacity .5. Then after 5 seconds or so, text 2 is opacity 1, and text 1 and three are opacity .5... so on in a cycle.
Can someone give me a hint/direction on how to do this in jquery please. Thank you in advance.

how in uibinder grid set text in specified cell

<g:Grid>
<g:row>
<g:customCell>
<g:HTMLPanel styleName="{style.loginPrompt}">
<div>
<ui:msg description="LoginPrompt">Please <b>Log In</b></ui:msg>
</div>
</g:HTMLPanel>
</g:customCell>
</g:row>
...
I want that my cell text will be in second cell like in java:
Grid g = new Grid(5, 5);
g.setText(0, 1, "asdf");
If you want 5 rows and 5 columns, I think you have to define them all in the UiBinder using the appropriate number of g:row and g:cell (or g:customCell). There's no equivalent to setText but you can do the equivalent of setHTML by using a g:cell (and g:customCell is equivalent to setWidget).
<g:Grid>
<g:row>
<g:customCell><!-- whatever --></g:customCell>
<g:cell>asdf</g:cell>
<!-- continue here for 5 rows, 5 cells per row -->