How can I call multiple values from the element with the same name with xpath? - xpath

I want the last two <dd> elements so that the output will read, Talstrasse 2A 01816 Berggiesshübel
here is the html snippet
<dt>Öffnungszeiten:</dt>
<dd>10:00 - 17:00</dd> <dt>Veranstaltungsart:</dt>
<dd> Herbstmarkt</dd> <dt>Veranstaltungsort:</dt>
<dd> Besucherbergwerk "Marie Louise Stolln" Berggiesshübel</dd> <dt>Strasse:</dt>
<dd>Talstrasse 2A,</dd>
<dt>PLZ / Ort:</dt>
<dd> 01816 Berggiesshübel </dd>
here is the suggested xpath my software gives me.
//div[contains(concat (" ", normalize-space(#class), " "), " container ")]/section[contains(concat (" ", normalize-space(#class), " "), " row event-details ")]/div[1]/div[3][contains(concat (" ", normalize-space(#class), " "), " bg-normal pal mbm ")]/div[1][contains(concat (" ", normalize-space(#class), " "), " row ")]/div[1]/dl[1][contains(concat (" ", normalize-space(#class), " "), " dl-horizontal event-detail-dl ")]/dd[6] | //html/body/div/section/div[1]/div[3]/div[1]/div[1]/dl[1]/dd[6]
can anyone help me?

The last two dd elements would be (//dd)[position() >= last() - 1]. In XPath 2.0 and higher you can get a single string using the string-join function e.g. string-join((//dd)[position() >= last() - 1], ' ').

Related

How to ignore SQL Query part of WHERE conditionally in JPA Query

I am wondering if it is possible to ignore part of query (not whole where part) conditionally. I have query in JPA
#Query("SELECT DISTINCT new it.akademija.wizards.models.document.DocumentGetReviewCommand(" +
"d.author.firstname, d.author.lastname, d.id, d.title, d.description, d.documentType.title, d.submissionDate)" +
" FROM Document d" +
" JOIN d.documentType dt" +
" JOIN dt.reviewUserGroups rug" +
" JOIN rug.users u WHERE u.username = :username" +
" AND d.documentState = it.akademija.wizards.enums.DocumentState.SUBMITTED" +
" AND u <> d.author" +
" **AND (lower(CONCAT(d.author.firstname, ' ', d.author.lastname)) like %:searchFor% " +
" OR lower(d.title) like %:searchFor%" +
" OR lower(d.description) like %:searchFor%" +
" OR lower(d.id) like %:searchFor%" +
" OR lower(dt.title) like %:searchFor%)")
Page<DocumentGetReviewCommand> getDocumentsForReview(#Param(value = "username") String username,
#Param(value = "searchFor") String searchFor,
Pageable pageable);
How can I ignore below part if searchFor param is null or blank ("")
AND (lower(CONCAT(d.author.firstname, ' ', d.author.lastname)) like %:searchFor% " +
" OR lower(d.title) like %:searchFor%" +
" OR lower(d.description) like %:searchFor%" +
" OR lower(d.id) like %:searchFor%" +
" OR lower(dt.title) like %:searchFor%)
You could just try adding logic which allows these conditions to be skipped should the search for term be null or empty:
AND
(COALESCE(:searchFor, '') = '' OR
(LOWER(CONCAT(d.author.firstname, ' ', d.author.lastname)) LIKE %:searchFor% OR
LOWER(d.title) LIKE %:searchFor%" OR
LOWER(d.description) LIKE %:searchFor% OR
LOWER(d.id) LIKE %:searchFor% OR
LOWER(dt.title) like %:searchFor%))

Random quote generator repeats the same quotes, why?

Good day to everyone! There is a quote generator made with Shoes.
#think.click do
#noun_nominative.shuffle
#base.shuffle
#thought.replace(#base.sample)
end
#noun_nominative =
[
"word1", "word2", "word3", "word4",
"word5", "word6", "word7", "word8"
]
#noun_accusative =
[
"word1", "word2", "word3"
]
#base =
[
#noun_nominative.sample.capitalize + "regular quote",
"Regular quote" + #noun_nominative.sample,
"Regular quote" + #noun_accusative.sample,
"Regular quote" + #noun_accusative.sample,
#noun_nominative.sample.capitalize + "regular quote",
"And another one base for a quote"
]
It simply replaces phrases in base array with random words from noun_nominative and noun_accusative, showing a new quote every time button "think" is clicked.
The program should make a brand new quote with every click, however, it keeps showing the same phrases which were generated once. How could I make it regenerate the quotes without reopening the program?
Thank you for answering!
You need to generate random quote on each click, rather than pre-generating them at app startup. This should be the laziest change to do what you want:
def generate_random_quote(nominative, accusative)
all_generated_quotes = [
nominative.sample.capitalize + " - это всякий, кто стремится убить тебя, неважно на чьей он стороне.",
"Иногда " + nominative.sample + " не попадает в " + accusative.sample + ", но " + nominative.sample + " не может промахнуться.",
"Нет ничего труднее, чем гибнуть, не платя смертью за " + accusative.sample + ".",
"Индивидуумы могут составлять " + accusative.sample + ", но только институты могут создать " + accusative.sample + ".",
nominative.sample.capitalize + " - это тот человек, который знает о вас все и не перестает при этом любить вас.",
"Трудно себе представить, что сталось бы с человеком, живи он в государстве, населенном литературными героями."
]
all_generated_quotes.sample
end
#think.click do
freshly_baked_random_quote = generate_random_quote(#noun_nominative, #noun_accusative)
#thought.replace(freshly_baked_random_quote)
end
It is, of course, rather wasteful. It generates all possible quotes and discards all but one. If that's a concern, fixing that would be your homework. :)

loading value from element using xpath

I'm kinda new to xpath. So I don't know how to do this. I have this file
<map>
<object name="object (1)">
<position>564.014893 -7424.033691 35.448875</position>
<rotation>0.000000 0.000000 0.000000</rotation>
<model>3494</model>
</object>
</map>
As you can see in position;
564.014893 -7424.033691 35.448875
564.014893 is X
-7424.033691 is Y
35.448875 is Z
How do I load X(or Y/Z)?
If you have xpath 2 support, you can use tokenize to split the string on spaces. The X, Y and Z values would respectively be:
tokenize(map/object/position, ' ')[1]
tokenize(map/object/position, ' ')[2]
tokenize(map/object/position, ' ')[3]
If you only have xpath 1 support, you could use the substring-before and substring-after methods. The X, Y, and Z values would respectively be:
substring-before(map/object/position, " ")
substring-before(substring-after(map/object/position, " "), " ")
substring-after(substring-after(map/object/position, " "), " ")

Carrying an ID with strings to a next page

I'm trying to carry the ID to the next page, but all i manage to get is review.php?ID= without the ID.
Here is the code:
html = html + "Name:" + name + "Type : " + type + "Location : " + location + '<input type="button" value="Write a review!" onclick=parent.location="review.php?ID=" ('+ ID +') />' + "<br/>";
Thanks in advance for any help.
There's a couple things wrong here. You have mismatched quotes (single and double), and I'm pretty sure the id shouldnt have spaces round it with parens. The embeded quotes need to be escaped, too
something like this:
html = html + "Name:" + name + "Type : " + type + "Location : " + location +
"<input type='button' value='Write a review!' onclick='parent.location=\"review.php?ID=("+ID+")\" />" + "<br/>";

Issue using Oracle date function with Spring's NamedParamenterJdbcTemplate

I'm having an issue trying to get my SQL query which works fine in SQL Developer (Oracles free database tool) to also work using Spring's NamedParameterJdbcTemplate class.
My query is:
String sql = " SELECT COUNT(*) FROM ( " +
" SELECT FE.USR_ID, MAX(FE.DATE_FIRST_SUB) AS SUB_DATE " +
" FROM FC, FE " +
" WHERE FC_STATUS = 'MEMBER' " +
" AND FC.FC_SPC_ID = :spcId " +
" AND FE.FE_USR_ID = FC.FC_USR_ID " +
" AND FE.DATE_FIRST_SUB IS NOT NULL " +
" GROUP BY FE_USR_ID " +
" ) " +
" WHERE SUB_DATE BETWEEN TO_DATE('01-JUN-2011', 'DD-MON-YYYY') AND TO_DATE('01-JUL-2011', 'DD-MON-YYYY') ";
It has something to do with my dates, formatting perhaps? When I don't use the WHERE clause in the outer select it works, when it's included 0 is returned from the count - as I mentioned running the SQL directly returns expected results.
Any advice?
Thanks.
Oh my, I was in fact looking at the wrong database!!

Resources