Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 02-26-2015, 02:34 PM   #1
chaot
Head of lunatic asylum
chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.
 
chaot's Avatar
 
Posts: 349
Karma: 77620
Join Date: Jun 2012
Location: UTC +1
Device: Tolino Vision 3HD
XPath Tutorial - vbq (very basic question)

Hola!

I have now tried the whole afternoon to understand the XPath Tutorial and read some not so compelling things about XML-files etc. - no luck.

I have also created the Sample-ebook.

Please tell me where/how I need to make such a document/text or in which form to bring so with the given search pattern in the tutorial eg. // h: h2 or // * [@ class = "chapter"] I can somehow make a hit.

Sometimes the formulation of a question is already a problem.

Last edited by chaot; 02-26-2015 at 02:42 PM.
chaot is offline   Reply With Quote
Old 02-26-2015, 02:44 PM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
That searchpattern is designed to match all h2 tags (regex: <h2( [^>]*)?>), as well as all tags of class "chapter" (regex: <\w+ class="chapter">)
eschwartz is offline   Reply With Quote
Old 02-27-2015, 05:07 AM   #3
chaot
Head of lunatic asylum
chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.
 
chaot's Avatar
 
Posts: 349
Karma: 77620
Join Date: Jun 2012
Location: UTC +1
Device: Tolino Vision 3HD
The Sample ebook says: A very short ebook to demonstrate the use of XPath.
How can I let this 'Very short ebook' demonstrate me the use of XPath?

No matter what search term // h: h2 or // * [@ class = "chapter"] or <h2( [^>]*)?> or <\w+ class="chapter"> the result is: No matches were found for ...

That specific question needs more a practical answer.
Attached Thumbnails
Click image for larger version

Name:	h: h2.png
Views:	154
Size:	166.2 KB
ID:	135377   Click image for larger version

Name:	w+ class=%22chapter%22>.png
Views:	164
Size:	171.8 KB
ID:	135378  
chaot is offline   Reply With Quote
Old 02-27-2015, 05:27 AM   #4
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,155
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
You don't use the XPATH settings in the regular search area.

Try clicking on Tools | Table of Contents | Edit Table of Contents and then there is a button Generate ToC from XPath
PeterT is offline   Reply With Quote
Old 02-27-2015, 09:44 AM   #5
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,071
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
XPath has some other uses, but all I've used it for is making table of contents (screen shot)

In the F&R you can only use Regular Expressions

http://manual.calibre-ebook.com/regexp.html

Using eschwartz's RE you can find H2's with class="chapter" in the sample book (pic 2)

I guess I'm not understanding why you were looking to use XPath. Sorry, but maybe you could provide a little more about what you were looking to do?
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	191
Size:	141.4 KB
ID:	135394   Click image for larger version

Name:	Capture2.JPG
Views:	168
Size:	100.5 KB
ID:	135395  

Last edited by phossler; 02-27-2015 at 09:56 AM.
phossler is offline   Reply With Quote
Old 02-27-2015, 10:51 AM   #6
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
@chaot -- as PeterT said.
And the regex did not work because you were in normal mode, not regex mode. The S&R can take regexes, like the translation I supplied, if treated correctly. xpath is totally different.
eschwartz is offline   Reply With Quote
Old 02-27-2015, 02:08 PM   #7
chaot
Head of lunatic asylum
chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.
 
chaot's Avatar
 
Posts: 349
Karma: 77620
Join Date: Jun 2012
Location: UTC +1
Device: Tolino Vision 3HD
The original to start with, see A very short ebook.

Quote:
Originally Posted by PeterT View Post
You don't use the XPATH settings in the regular search area.

Try clicking on Tools | Table of Contents | Edit Table of Contents and then there is a button Generate ToC from XPath
Or just use the button ToC (see Button-Edit the Table of Contents). But this button (from general calibre window) is more for to see the ToC than to edit, even so possible.

So you are quite right to mention the 'path': without Edit book window we wouldn't know the correct 'key phrases' to use (see Edit the ToC in ... (Start) after Fix HTML + Beautify current file)

In a (very) small ebook creating the ToC its enough to fill the libprs500 window only HTML tags with tag names (like a, br, div, h1, h2 etc.) and ignore the attribute and value inputs. That's probably in bigger ebooks not to ignore in order to obtain a really sophisticated ToC (at moment I don't know).

Here results the same if using only //h:h1 or (full expression) //h:h1[re:test(@class, "bookTitle", "i")] - tested.

See Create ToC from XPath and the result Edit the ToC in ...(vers A).
Note: The HTML tags div and h2 get id-numbers (both h2 different ones), but the HTML tag h1 gets none. Can you say something about?

It's possible to customize the ToC, see Edit the ToC in ...(vers B)

Quote:
Originally Posted by phossler View Post
and then comes Python. Probably more questions in future.

Quote:
... why you were looking to use XPath. Sorry, but maybe you could provide a little more about what you were looking to do?
I like to edit a fair amount of books. Success often has to do with proper, well-known tools (calibre and around).
As a sailor I like to navigate, preferably in new territories.

Quote:
Originally Posted by eschwartz View Post
... the regex did not work because you were in normal mode, not regex mode. The S&R can take regexes, like the translation I supplied, if treated correctly. xpath is totally different.
As we are already a bit further! I would also like to know something about regex mode. Beside of what is described in regular expressions - a practical aspect maybe. S&R??? Please!

Correct treatment, very important.

There are some between us you'll explain dozen times the theory or even better once the practice.

XPath Tutorial is great (as far as I can tell). Only a small but not unimportant hint is missing: where you can do something with it. ToC or 'Table of content' isn't mentioned even once.

My pictures show details, always different ones.
Attached Thumbnails
Click image for larger version

Name:	A very short ebook.png
Views:	156
Size:	96.9 KB
ID:	135407   Click image for larger version

Name:	Button-Edit the Table of Contents.png
Views:	160
Size:	85.6 KB
ID:	135408   Click image for larger version

Name:	Edit the ToC in ...(Start).png
Views:	163
Size:	202.6 KB
ID:	135409   Click image for larger version

Name:	Create ToC from XPath.png
Views:	155
Size:	47.3 KB
ID:	135410   Click image for larger version

Name:	Edit the ToC in ...(vers A).png
Views:	159
Size:	143.0 KB
ID:	135411   Click image for larger version

Name:	Edit the ToC in ...(vers B).png
Views:	144
Size:	155.8 KB
ID:	135412  

Last edited by chaot; 03-02-2015 at 04:57 AM. Reason: corrected language
chaot is offline   Reply With Quote
Old 02-27-2015, 04:57 PM   #8
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
For regex, usage is as described at the end of the tutorial, in the section "I think I’m beginning to understand these regular expressions now... how do I use them in calibre?"

XPath instructions start here: http://manual.calibre-ebook.com/conv...le-of-contents and link to the XPath tutorial.

For a more general and in depth explanation of the power of regexes, my favorite site remains this one: http://www.regular-expressions.info/
eschwartz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested TOC / Xpath question halfgone Conversion 0 02-13-2012 07:46 PM
Xpath question: Two Expressions for Level 1 redcloud111 Calibre 2 01-28-2012 12:46 AM
two 'basic tutorial' questions affa Sigil 12 04-21-2011 02:38 PM
XPath question krischik Calibre 0 01-16-2010 08:22 AM
Basic tutorial please (for Dummies) captaingeorges Bookeen 6 03-02-2008 02:28 PM


All times are GMT -4. The time now is 04:37 AM.


MobileRead.com is a privately owned, operated and funded community.