Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-29-2017, 03:53 AM   #1
a.o.advena
Junior Member
a.o.advena began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2017
Device: none
Help with XPath Expression

I'm trying to convert a book from ODT to EPUB, but I'm having problems with the XPath expression for chapter breaks. My document has specific custom formatting at each break, which (using the suggestion from the "Chapter Detection/Table of Contents Tutorial" sticky) I determined to be:

Code:
<p class="P-Section_20_Number">
AND
Code:
<p class="P-Chapter_20_Number c_odt2">
I tried a few different things from the Calibre XPath Tutorial (https://manual.calibre-ebook.com/xpa...xpath-tutorial) but nothing seems to be working.

Would appreciate any help.
a.o.advena is offline   Reply With Quote
Old 01-29-2017, 07:48 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,916
Karma: 22669818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Code:
//h:p[@class="P-Section_20_Number]|//h:p[@class="P-Chapter_20_Number c_odt2"]
kovidgoyal is offline   Reply With Quote
Advert
Old 02-05-2017, 07:54 AM   #3
a.o.advena
Junior Member
a.o.advena began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2017
Device: none
Thanks for your response. I just tried to use this (pasted the line above into "Detect chapters as (XPath expression):" but Calibre says that the expression is invalid.

In case I wasn't clear above, I want it to break at either one of the above classes.

Last edited by a.o.advena; 02-05-2017 at 07:57 AM.
a.o.advena is offline   Reply With Quote
Old 02-05-2017, 08:05 AM   #4
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,906
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by a.o.advena View Post
Thanks for your response. I just tried to use this (pasted the line above into "Detect chapters as (XPath expression):" but Calibre says that the expression is invalid.

In case I wasn't clear above, I want it to break at either one of the above classes.
There is a double quote missing before the first close square bracket. It should be:
Code:
//h:p[@class="P-Section_20_Number"]|//h:p[@class="P-Chapter_20_Number c_odt2"]
davidfor is offline   Reply With Quote
Old 02-05-2017, 11:15 PM   #5
a.o.advena
Junior Member
a.o.advena began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2017
Device: none
Thanks for catching the error. I tried this new expression, but no luck. I still get all the section & chapters in one big xml file.

For kicks, I did a little more experimentation and tried some other combos based on the manual and wizard
Code:
//h:p[@class="P-Chapter-Number c_odt0"]
Code:
//*[@class="P-Chapter-Number c_odt0"]
Code:
//*[re:test(@class, "P-Chapter-Number c_odt0", "i")]
all with the same result.
a.o.advena is offline   Reply With Quote
Advert
Old 02-06-2017, 12:54 AM   #6
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,906
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Is it the same class for all the paragraphs you want to split on? Or does the number in "P-Chapter_20_Number" change? Is that "20" actually the chapter number? If that is the case, the your last test is getting close. I think the following should do it:

Code:
//*[re:test(@class, "P-Chapter", "i")]
And as you had to different classes in the first post, it would be:

Code:
//*[re:test(@class, "P-Chapter|P-Section", "i")]
If that doesn't work, and my spelling is correct, I think we need to see a sample of the book to get an idea of what to do.
davidfor is offline   Reply With Quote
Old 02-20-2017, 06:28 AM   #7
a.o.advena
Junior Member
a.o.advena began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2017
Device: none
Quote:
Originally Posted by davidfor View Post
Is it the same class for all the paragraphs you want to split on? Or does the number in "P-Chapter_20_Number" change? Is that "20" actually the chapter number?
The classes are all the same. The "_20_" is what Calibre or LibreOffice (not sure which) substitutes for the space that is in the style's name.

Quote:
Originally Posted by davidfor View Post
I think the following should do it:

Code:
//*[re:test(@class, "P-Chapter", "i")]
And as you had to different classes in the first post, it would be:

Code:
//*[re:test(@class, "P-Chapter|P-Section", "i")]
Yes, that's the ticket. Perticularly the second one as it captures both the chapter and section breaks. (For others who may use this later - I still had to do a little manual tweaking of the TOC, but this took care of breaking everything up into separate files that could then be arraigned in the TOC.)

Thanks for your help.
a.o.advena is offline   Reply With Quote
Reply

Tags
chapter detection, odt to epub, xpath


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath Expression Coding doylejohn Calibre 5 03-02-2015 07:33 PM
Xpath Expression list JimLL Conversion 4 04-08-2012 02:29 PM
Xpath TOC Expression Agama Calibre 2 07-12-2010 02:24 AM
XPath Expression wizard?? tonyx3 Calibre 1 01-26-2010 04:49 AM
XPath Expression Wizard Error Crusader Calibre 4 12-27-2009 12:09 PM


All times are GMT -4. The time now is 08:38 PM.


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