Get the level of nodes - xslt

I want to get the level of <li> in my input
input:
<ol start="1" style="1">
<li>
<p type="List Number Level 1">Text 1.</p>
</li>
<li>
<p type="List Number Level 1">Text 2</p>
<ol start="1">
<liFormat><iRef style="a"/>)<t/></liFormat>
<li>
<p type="List Number Level 2">Text 3.</p>
</li>
<li>
<p type="List Number Level 2">Text 4.</p>
</li>
</ol>
</li>
<li>
<p type="List Number Level 1">Text 5.</p>
</li>
</ol>
Output should be :
<ol start="1" style="1">
<li>
<p type="List_1_First">Text 1.</p>
</li>
<li>
<p type="List_1_First">Text 2</p>
<ol start="1">
<liFormat><liRef style="a"/>)<t/></liFormat>
<li>
<p type="List_2_First">Text 3.</p>
</li>
<li>
<p type="List_2_First">Text 4.</p>
</li>
</ol>
</li>
<li>
<p type="List_1_First">Text 5.</p>
</li>
</ol>
Tried code :
<xsl:template match="ol[#start]/li[1]/p[contains(#type,'List')]" priority="30">
<p type="List_{count(li)}_First">
<xsl:apply-templates/>
</p>
</xsl:template>
Here all things have been implemented as i expected. But I have to take the level of li. ex : List_{li level}_First . Nut that par not working properly. I have mentioned my tried code. I am using xslt 2.0.
Thank you

I think you need to count the ancestors here:
<tps:p type="List_{count(ancestor::tps:li)}_First">
Maybe you have other templates in your XSLT, but your current template only matches the first li element under the ol. To get your expected output, maybe you need to do this...
<xsl:template match="tps:ol[#start]/tps:li/tps:p[contains(#type,'List')]" priority="30">
See http://xsltfiddle.liberty-development.net/gWEamKJ for an example.

Related

How to display my footer in every page when my report is more than one page

i have customized reports and i notice that when i have a report composed of more than one page my footer displays only in the first page however i want my footer displays in all pages . I'm using odoo 9. Any help please ? Here is my code
<div class="footer" style="position:absolute;bottom:-1115px">
<div class="text-center" style="border-top: 1px solid black;">
<small>
<ul t-if="not company.custom_footer" class="list-inline">
<li t-if="company.phone">Phone:
<span t-field="company.phone"/>
</li>
<li t-if="company.fax and company.phone">&bull;</li>
<li t-if="company.fax">Fax:
<span t-field="company.fax"/>
</li>
<li t-if="company.email and company.fax or company.email and company.phone">
&bull;
</li>
<t t-if="company.vat">TVA:
<span t-field="company.vat"/>
</t>
<li t-if="company.company_registry">RC:
<span t-field="company.company_registry"/>
</li>
</ul>
</small>
<small>
<ul class="list-inline">
<t t-set="nbr_page" t-value="1"/>
<li>Page:</li>
<t t-set="compteur" t-value="nbr_page+1"/>
<li>
<span class="page"/>
<t t-esc="nbr_page"/>
</li>
/
<t t-esc="nbr_page"/>
<li>
<span class="topage"/>
</li>
</ul>
</small>
<t t-set="nbr_page" t-value="1"/>
<t t-set="compteur" t-value="nbr_page+1"/>
</div>
</div>

Delete all <li> and </li> tags inside ul class

I would like to delete all <li> and </li> tags inside ul class in notepad++
here is example:
<ul class="test">
<li>
<img title="test" alt="test" src="http://test.jpg" width="50" height="50">
</li>
<li>
<img title="test" alt="test" src="test" width="50" height="50">
</li>
</ul>
to achieve this:
<ul class="test">
<img title="test" alt="test" src="http://test.jpg" width="50" height="50">
<img title="test" alt="test" src="test" width="50" height="50">
</ul>
I think this will solve my problem:
Serach for
((?-s)<ul.+test(?s).+?)<li> and
((?-s)<ul.+test(?s).+?)</li>
replace it by \1

selecting values of tags within tags

this is a part of the html code i'm interested in:
<div class="mreinfwpr" id="mhd">
<p class="mreinfp">Hours of Operation (View all)(Show less)</p>
<ul id="hroprt" class="alstdul">
<li class="mreinfli">
<span class="mreinflispn1">Today</span><span class="mreinflispn2"><span>11:30 am - 11:30 pm</span>
</span><span class="mreinflispn3">Closed Now</span> </li>
</ul>
<!-- View All Work Timings Vertically -->
<ul class="alstdul dn" id="statHr">
<li class="mreinfli">
<span class="mreinflispn1"> Monday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
<li class="mreinfli">
<span class="mreinflispn1"> Tuesday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
<li class="mreinfli">
<span class="mreinflispn1"> Wednesday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
<li class="mreinfli">
<span class="mreinflispn1"> Thursday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
<li class="mreinfli">
<span class="mreinflispn1"> Friday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
<li class="mreinfli">
<span class="mreinflispn1"> Saturday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
<li class="mreinfli">
<span class="mreinflispn1"> Sunday </span><span class="mreinflispn2">11:30 am - 11:30 pm</span>
</li>
</ul>
</div>
<div class="mreinfwpr">
<p class="mreinfp">Also Listed in</p>
<ul class="alstdul">
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Pubs-<near>-Indira-Nagar-2nd-Stage/ct-1000027567" title="Pubs in Indira-Nagar-2nd-Stage, Bangalore">Pubs</a>
<!-- <li class="spc"></li> -->
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Pizza-Outlets-<near>-Indira-Nagar-2nd-Stage/ct-50105" title="Pizza Outlets in Indira-Nagar-2nd-Stage, Bangalore">Pizza Outlets</a>
<!-- <li class="spc"></li> -->
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Restaurants-<near>-Indira-Nagar-2nd-Stage/ct-304085" title="Restaurants in Indira-Nagar-2nd-Stage, Bangalore">Restaurants</a>
<!-- <li class="spc"></li> -->
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Lounge-Bars-<near>-Indira-Nagar-2nd-Stage/ct-597637" title="Lounge Bars in Indira-Nagar-2nd-Stage, Bangalore">Lounge Bars</a>
<!-- <li class="spc"></li> -->
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Microbrewery-Pubs-<near>-Indira-Nagar-2nd-Stage/ct-1041785821" title="Microbrewery Pubs in Indira-Nagar-2nd-Stage, Bangalore">Microbrewery Pubs</a>
<!-- <li class="spc"></li> -->
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Nightlife-Restaurants-<near>-Indira-Nagar-2nd-Stage/ct-1041746883" title="Nightlife Restaurants in Indira-Nagar-2nd-Stage, Bangalore">Nightlife Restaurants</a>
<!-- <li class="spc"></li> -->
<li>
<a onclick="_ct('alsocat', 'dtpg', '17592186044416');" href="http://www.justdial.com/Bangalore/Foodie-Delight-<near>-Indira-Nagar-2nd-Stage/ct-1041818989" title="Foodie Delight in Indira-Nagar-2nd-Stage, Bangalore">Foodie Delight</a>
<!-- <li class="spc"></li> -->
<!-- <li class="spc"></li> -->
<!-- <li class="spc"></li> -->
<!-- <li class="spc"></li> -->
<li>
<a href="javascript:void(0);" onclick="_ct('morlstdin', 'dtpg');
openDiv('alsp');">more...</a>
</li>
</ul>
</div>
<div class="mreinfwpr">
<p class="mreinfp">Services</p>
<span class="srihd">General</span>
<ul class="alstdul">
<!-- <tr > -->
<li><img class="srimg" src="http://www.justdial.com/public/images/icon/bar.png" width="20" height="20" /><span class="sritxt">Bar </span></li>
<!-- <td class="spc"></td> -->
<li><img class="srimg" src="http://www.justdial.com/public/images/icon/checkmarkNew.png" width="20" height="20" /><span class="sritxt">Outdoor Seating </span></li>
<!-- </tr> -->
<!-- <tr > -->
<li><img class="srimg" src="http://www.justdial.com/public/images/icon/checkmarkNew.png" width="20" height="20" /><span class="sritxt">Alcohol </span></li>
<!-- <td class="spc"></td> -->
<li><img class="srimg" src="http://www.justdial.com/public/images/icon/checkmarkNew.png" width="20" height="20" /><span class="sritxt">AC </span></li>
<!-- </tr> -->
<!-- <tr class="reset" > -->
<li><img class="srimg" src="http://www.justdial.com/public/images/icon/checkmarkNew.png" width="20" height="20" /><span class="sritxt">WiFi </span></li>
<!-- <td class="spc"></td> -->
<li><img class="srimg" src="http://www.justdial.com/public/images/icon/checkmarkNew.png" width="20" height="20" /><span class="sritxt">Dinein </span></li>
<!-- </tr> -->
</ul>
</div>
<div class="mreinfwpr">
<p class="mreinfp">Modes of Payment</p>
<ul class="alstdul">
<li>Cash</td>
<!-- <td class="spc"></td> -->
<li>Master Card</td>
</li>
<li>Visa Card</td>
<!-- <td class="spc"></td> -->
<li>Debit Cards</td>
</li>
<li>Credit Card</td>
<!-- <td class="spc"></td> -->
</div>
<div class="mreinfwpr">
<p class="mreinfp">Year Established</p>
<ul class="alstdul">
<li> 2010</li>
</ul>
</div>
i want data which are in "also listed in" category. i.e:
Also Listed in
Pubs
Pizza Outlets
Restaurants
Lounge Bars
Microbrewery Pubs
Nightlife Restaurants
Foodie Delight
more...
i tried using :
also_listed_in=bSoup.findAll("a", { "onclick" : "_ct('alsocat', 'dtpg', '17592186044416');" })
I was able to obtain the required data. But the problem is that the attribute within the "a" tag, i.e., onclick = _ct('alsocat', 'dtpg', '17592186044416')
keeps changing with different url of same kind. But I've observed that _ct('alsocat', 'dtpg' part of _ct('alsocat', 'dtpg', '17592186044416') is same for all similar urls.
Please help me obtain the required data.
You can use the part of the onclick text that does not change to get what you want:
from bs4 import BeautifulSoup
import re
soup = BeautifulSoup(html)
print(soup.find_all("a",onclick=re.compile(r"_ct\('alsocat', 'dtpg'")))
If _ct('alsocat' is unique to those urls then you can just use a css startswith selector:
print(soup.select("a[onclick^=_ct('alsocat']"))

How can i find the last number in tags

for passing the pagination of a site with python, i want to find the last page of a website.
i inspect the element of the page by firebug
<div class="pagination">
<ul>
<li>
<a>
<img src="/images" class="pagination-l">
</a>
</li>
<li style="float:left;">
<a id="toPage" title="A" class="page-number actif" href="/d">
1
</a>
</li>
<li style="float:left;">
<a id="toPage_0" title="A2" class="p" href="/ew">
2
</a>
</li>
<li style="float:left;">
<a id="toPage_1" title="A3" class="p3" href="/t3">
3
</a>
</li>
<li style="float:left;">...</li>
<li style="float:left;">
<a id="toPage_2" title="t" class="p" href="t2">
5
</a>
</li>
<li>
<a id="nextPage" title="next(2)" href="/test1">
<img src="test.png" class="pagination-r">
</a>
</li>
</ul>
</div>
Here the number that i want is 5
Use a combination of a parser and regex:
from bs4 import BeautifulSoup
import re
html = your_html_here
soup = BeautifulSoup(html, "html5lib")
links = soup.findAll('a', text=re.compile('^\s*\d+\s*$'))
number = links[-1].string.strip()
print number
# 5
See a demo on ideone.com

Search Box Hides Links

I'm wondering if this is a Foundation bug, or if I've missed something in my code. My nav bar is structured as follows:
<div class="sticky noprint">
<nav class="top-bar" data-topbar role="navigation">
<ul class="title-area">
<!-- This li needs to be here for for some strange reason to make the mobile menu work -->
<li class="name">
<!-- <h1>Home</h1> -->
</li>
<li class="toggle-topbar menu-icon">
<span>Menu</span>
</li>
</ul>
<section class="top-bar-section">
<!-- Left Nav Section -->
<ul class="left">
<!-- Class Dropdown -->
<!-- <li><img src="background180.png" alt="background120" width="225" height="60"></li> -->
<li class="has-dropdown">
Courses
<ul class="dropdown">
<li>All Classes</li>
<li class="has-dropdown">
Course Admin
<ul class="dropdown">
<li>Search for a Course</li>
<li>Edit a Course</li>
<li>Add a Course</li>
</ul>
</li>
</ul>
</li>
<!-- Class Dropdown Ends -->
<!-- Learner Dropdown -->
<li class="has-dropdown">
Learner
<ul class="dropdown">
<li>Search for a Learner</li>
<li>Add a Learner</li> <li>Edit a Learner</li>
<li>List All Active Learners</li>
</ul>
</li>
<!-- Learner Dropdown Ends -->
<!-- Grades Dropdown -->
<li class="has-dropdown">
Grades
<ul class="dropdown">
<li class="has-dropdown">
View and Enter Grades
<ul class="dropdown">
<li>All Courses</li>
</ul>
</li>
<li class="has-dropdown">
Grade Templates
<ul class="dropdown">
<li>Create Template</li>
<li>Active Templates</li>
<li>All Templates</li>
</ul>
</li>
</ul>
</li>
<!-- Grades Dropdown Ends -->
<!-- Employee Dropdown -->
<li class="has-dropdown">
Employee
<ul class="dropdown">
<li>Add an Employee</li>
<li>Edit an Employee</li>
<li>Search for an Employee</li>
</ul>
</li>
<!-- Employee Dropdown Ends -->
<!-- Reports Dropdown -->
<li class="has-dropdown">
Reports
<ul class="dropdown">
<li class="has-dropdown">
Program
<ul class="dropdown">
<li>New Registrations</li>
<li>Email All Active Students</li>
<!-- <li>Email All Active Students Using Your Default Client</li> -->
<li>Weekly Course Report (Your Courses)</li>
<li>Weekly Course Report (Active Courses)</li>
<li>Weekly Class Report (Inactive Courses)</li>
<li>Grades</li>
<li>Grades (Old System)</li>
<!-- <li>Program Totals</li> -->
<!-- <li>IMS Action</li> -->
<!-- <li>Exited Needs Action</li> -->
</ul>
</li>
<li class="has-dropdown">
Reporting
<ul class="dropdown">
<li>New Reg CSV for</li>
<li>New Reg CSV for</li>
<li>Active - No</li>
<li>Action</li>
<li>Exit 3-Month Follow-up</li>
<li>Exit 6-Month Follow-up</li>
<li>Exit 12-Month Follow-up</li>
</ul>
</li>
<li class="has-dropdown">
Counsellor
<ul class="dropdown">
<li>100 Day No Attendance</li>
<li>Active - No Classes</li>
<!-- <li>Pause 3-Month Follow-up</li> -->
<!-- <li>All Paused Students</li> -->
</ul>
</li>
<li class="has-dropdown">
DUP
<ul class="dropdown">
<li>Active - No</li>
<li>Banner Action</li>
<li>Exit 3-Month Follow-up</li>
<li>Exit 6-Month Follow-up</li>
<li>Exit 12-Month Follow-up</li>
<li>100 Day No Attendance</li>
<li>Active - No Classes</li>
<!-- <li>Pause 3-Month Follow-up</li> -->
<!-- <li>All Paused Students</li> -->
<!-- <li>Exited Needs Action</li> -->
</ul>
</li>
</ul>
</li>
<li class="has-dropdown">
Account
<ul class="dropdown">
<!-- <li class="active">Right Button Active</li> -->
<li>Request Access</li>
<li>Report Bugs</li>
<li>Login</li>
<li>Edit Your Account</li>
<li>Logout</li>
</ul>
</li>
<!-- Reports Dropdown Ends -->
</ul>
<!-- Left Nav Ends -->
<!-- Right Nav Section -->
<ul class="right">
<li class="has-form">
<form name="form" action="select.php" method="get">
<div class="row collapse">
<div class="large-8 small-9 columns">
<input type="text" name="search" id="search" style="height: 29px" placeholder="">
</div>
<div class="large-4 small-3 columns">
<input type="submit" class="button expand" value="Search">
</div>
</div>
</form>
</li>
</ul>
<!-- End Right Nav Section -->
</section>
</nav>
</div>
So what I'm wondering is: Desktop works perfectly. When I shrink to mobile screen size, perform a search, the search bar now takes over the entire menu and won't show the hamburger menu as it's supposed to. Can anyone suggest a fix? Thanks so much in advance!