Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have lists with " · " (dot) in the html and output. I need to replace that with an actual <ul><li>...</li></ul>
This sounds tough but does anyone have any ideas?
The html is:
· List item 1
· List item 2
(wrapped in paragraph tags)
And I need it to be
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
</ul>
Delete the dot from the html and give the list a css of ul { list-style-type: circle; }
For more values for the css attribute, check http://www.w3.org/wiki/CSS/Properties/list-style-type
Related
This question already has answers here:
How can I set max-length in an HTML5 "input type=number" element?
(31 answers)
Regular Expression Test100-200
(1 answer)
Closed 4 years ago.
What pattern should i use to accept number range such as 100 - 200?
<input type="text" pattern="" name="numRange">
Also if it is possible to make sure the min is lower than max. i.e 100 - 200 here 100 should be lower than 200. Thanks!
As mentioned by revo in the comments you could validate a number range like so:
<form action="somefile.php">
<input type="number" step="1" min="100" max="200" id="numRange">
</form>
Regex Method (less recommended):
var input = document.getElementById('numRange');
input.oninvalid = function(event) {
event.target.setCustomValidity('number range should be betweeb 100-200')
}
<form action="somefile.php">
<input type="text" name="number" placeholder="100-200" pattern="^(1\d\d|200)$" id="numRange">
</form>
The main difference between the two methods is the first uses type="number", and the second relies regex, javascript and uses type="text").
I try to find all seconds tds among the descendants of div with the specified id, i.e. 22 and 222. The first solution that comes to my mind was:
//div[#id='indicator']//td[2]
but it selects only the first table cell, i.e. 22 but not both 22 and 222.
Then I replaced // with /descendant-or-self::node()/ and got the same result (obviously). But when I removed '-or-self' the xpath expression started to work as expected
test1 = test_tree.xpath(u"//div[#id='indicator']/descendant-or-self::node()/td[2]")
print len(test1) #prints 1 (first one: 22)
test1 = test_tree.xpath(u"//div[#id='indicator']/descendant::node()/td[2]")
print len(test1) #prints 2 (22 and 222)
Here is test HTML
<html>
<body>
<div id='indicator'>
<table>
<tbody>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr>
<td>11</td>
<td>22</td>
<td>33</td>
</tr>
<tr>
<td>111</td>
<td>222</td>
<td>333</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
I'm wondering why both expressions don't work identically since all the tds are descendants of div element no matter div included or not.
I think you have found a bug in your XPath processor.
I think I've found the cause of this issue:
http://www.w3.org/TR/xpath20/#id-errors-and-opt
"In some cases, a processor can determine the result of an expression without accessing all the data that would be implied by the formal expression semantics. For example, the formal description of filter expressions suggests that $s[1] should be evaluated by examining all the items in sequence $s, and selecting all those that satisfy the predicate position()=1. In practice, many implementations will recognize that they can evaluate this expression by taking the first item in the sequence and then exiting."
So there is no remedy. It's xpath processor implementation dependent however I still don't understand why //div[#id='indicator']/descendant-or-self::node()/td[2] and //div[#id='indicator']/descendant::node()/td[2] produce different results.
I developed a web page contains the HTML you provided in your question.
When you use this xpath:
.//div[#id='indicator']//tr/td[2]
It works as expected and the result is:
[u'<td>22</td>', u'<td>222</td>']
However, according to your comment, you were asking when .//td[2] doesn't work. The reason is .//td gives you a list of all the td(s) in your DOM. Adding an index such as [2] will result in the second td in that list
To sum up:
These are the results of applying .//td and .//td[2] respectively:
and if you want to take the text inside these tds, you should add /text() as the following:
Update:
The OP said:
So why then //div[#id='indicator']/descendant::node()/td[2] produces ['22', '222']? According to your comment: "Adding an index such as [2] will result in the second td in that list" it should populate only ['22'].
I will try to explain what is going on here:
descendant:node() doesn't equal to //
the equal to // is: descendant-or-self::node()
It is explained at W3C specification:
I hope this code could help you:
Is it possible to use schematron to ensure that the list items are in alphanumeric order?
<ul>
<li>1</li>
<li>a</li>
<li>d</li>
<li>g</li>
</ul>
Many thanks!
Yes, it is possible. You can use something like this example rule that reports all <li> elements whose value is lower than (lt) their previous <li> sibling value.
<sch:rule context="li">
<sch:report test=". lt preceding-sibling::li[1]">
This li value is lower than his previous li sibling value.
</sch:report>
</sch:rule>
I'm writing some Clojure code using Enlive to process a set of XML documents. They're in an XML format that borrows heavily from HTML but adds some custom tags, and my job is to convert them to real HTML. The custom tag that's bothering me the most right now is <tab>, which is being used in all kinds of places it shouldn't be. For example, it's often used to make lists which should really have been made with <ol> and <li>. Here's an example of the kind of thing I'm encountering:
<p class="Normal">Some text</p>
<p class="ListWithTabs">(a)<tab />First list item</p>
<p class="ListWithTabs">(b)<tab />Second list item</p>
<p class="ListWithTabs">(c)<tab />Third list item</p>
<p class="Normal">Some more text</p>
<p class="AnotherList">1.<tab />Another list</p>
<p class="AnotherList">2.<tab />Two items this time</p>
<p class="Normal">Some final text</p>
I want to turn this into:
<p class="Normal">Some text</p>
<ol type="a">
<li class="ListWithTabs">First list item</li>
<li class="ListWithTabs">Second list item</li>
<li class="ListWithTabs">Third list item</li>
</ol>
<p class="Normal">Some more text</p>
<ol type="1">
<li class="AnotherList">Another list</li>
<li class="AnotherList">Two items this time</li>
</ol>
<p class="Normal">Some final text</p>
To do this, I need to get the <p> elements that contain <tab> descendants (easy with Enlive selectors), and somehow cluster them according to the natural groupings they had in the original XML documents (much harder).
I've looked through the documents and determined that I can't rely on the class attribute: sometimes these <p>-that-should-be-<li> elements have the same class as the <p> elements around them, and sometimes there are two successive groups of <p>-that-should-be-<li> elements with the same class as each other (i.e., as if the example I posted had both clusters having the class ListWithTabs). The one thing I think I can rely on is that there are never two different lists without at least one non-list element separating them: in other words, any cluster of successive <p> elements which all have the property "has at least one <tab> element as a descendant" are all part of the same list.
With that in mind, I did some experimenting at the REPL, with Enlive loaded under the namespace e (that is, (require '[net.cgrand.enlive-html :as e]) should be assumed to be in effect for all the rest of my question). It was easy to write a selector to pick out the elements I want, but (e/select snippet [(e/has [:tab])]) returns a list (well, it's really a lazy sequence) of 5 elements. But what I want is a list of lists: the first with three elements and the second with two. Something vaguely like this (pardon the non-standard indentation):
[
[{:tag :p, :content (... "First list item" ...)}
{:tag :p, :content (... "Second list item" ...)}
{:tag :p, :content (... "Third list item" ...)}
] ; 3 items in first list
[{:tag :p, :content (... "Another list" ...)}
{:tag :p, :content (... "With just two items" ...)}
] ; 2 items in second list
]
I was able to create the following selectors:
(def first-of-tab-group [(e/has [:tab])
(e/left (complement (e/has [:tab])))])
(def rest-of-tab-group [(e/has [:tab])
(e/left (e/has [:tab]))])
But now I'm stuck. I'd like to do something like (e/select snippet [[(e/start-at first-of-tab-group) (e/take-while rest-of-tab-group)]]), but as far as I know Enlive doesn't have any functions like start-at and take-while.
It feels like I'm very close, but just missing one final key step. So how do I take the last step? How do I select just a "cluster" of elements that match certain rules, but omit other elements that would match the same rules but aren't part of that first "cluster"?
According to enlive documentation: {node-selector node-selector} we can group those with
{[:p.Normal] [:p.Normal]} assuming that is the delimiter.
Now, my question is: How do one iterates over the results inside each resulting group with enlive.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Where can i find a free service for reverse geocoding a coordinate in israel to get a street address? the google api web service doesnt give me a street address in israely coordinates...
Thanks.
Checkout
Find nearest Intersection and Find nearby Streets from GeoNames.org
For example:
http://ws.geonames.org/findNearestIntersectionOSM?lat=32.081&lng=34.781
returns:
<geonames>
<intersection>
<street1>אבן גבירול</street1>
<highway1>tertiary</highway1>
<street2>בלוך</street2>
<highway2>tertiary</highway2>
<lat>32.0813665</lat>
<lng>34.7813189</lng>
<distance>0.05</distance>
</intersection>
</geonames>
I am also searching.. found no free service, but Waze have a nice one for pay.
This is example I got from them:
http://rgc.waze.co.il/GeoCoding/decode?token=123&x=34.8735080868463&y=32.05829587571&r=0.001&max=3
Where:
token = is the token assigned to you (currently use 123)
x = Lon.
y = Lat.
r = distance to search the address (angle - 1 deg = 111.11 KM)
max = the number of max results
<result>
<address id="52778" type="1" street="גני תקווה" house="22">
</address>
<address id="52776" type="1" street="קישון" house="22">
</address>
<address id="52775" type="1" street="קישון" house="18">
</address>
</result>