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 08-28-2019, 04:11 PM   #1
mjcatt
Junior Member
mjcatt began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
Help with Create TOC from XPath

I'm not great with XPath, but I usually manage to stumble my way for what I need. However, I'm out of my league on this one and I'm hoping someone experienced can help.

I have a number of books that use the 'title' attribute in headers to specify the text that should be used in generating the TOC. Here's an example:

<h2 title='Text to place in TOC'>Text that goes into book itself</h2>

What XPath expression should be used in 'Create TOC from XPath' to return the value of the title attribute (i.e., 'Text to place in TOC')?

Thanks in advance for your help!
mjcatt is offline   Reply With Quote
Old 08-28-2019, 04:56 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,900
Karma: 55267620
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by mjcatt View Post
I'm not great with XPath, but I usually manage to stumble my way for what I need. However, I'm out of my league on this one and I'm hoping someone experienced can help.

I have a number of books that use the 'title' attribute in headers to specify the text that should be used in generating the TOC. Here's an example:

<h2 title='Text to place in TOC'>Text that goes into book itself</h2>

What XPath expression should be used in 'Create TOC from XPath' to return the value of the title attribute (i.e., 'Text to place in TOC')?

Thanks in advance for your help!
use the default From Headers. The Title attribute prevails when ther
theducks is offline   Reply With Quote
Old 08-28-2019, 06:16 PM   #3
mjcatt
Junior Member
mjcatt began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
Quote:
Originally Posted by theducks View Post
use the default From Headers. The Title attribute prevails when ther
If I use 'Generate TOC from all headers' it picks up the text between <h1></h1>, not the text in the title attribute. So for my example, what ends up going into the TOC is 'Text that goes into book itself'.

What I have noticed is that it will use the title attribute text only if there is no text between <h1></h1>. For example:

<h1 title='Attribute Text'></h1> puts 'Attribute Text' in the TOC, but:
<h1>title='Attribute text'>Book Text</h1> puts 'Book Text' into the TOC.

I wonder if I have a setting wrong somewhere...
mjcatt is offline   Reply With Quote
Old 08-28-2019, 07:09 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,900
Karma: 55267620
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by mjcatt View Post
If I use 'Generate TOC from all headers' it picks up the text between <h1></h1>, not the text in the title attribute. So for my example, what ends up going into the TOC is 'Text that goes into book itself'.

What I have noticed is that it will use the title attribute text only if there is no text between <h1></h1>. For example:

<h1 title='Attribute Text'></h1> puts 'Attribute Text' in the TOC, but:
<h1>title='Attribute text'>Book Text</h1> puts 'Book Text' into the TOC.
I wonder if I have a setting wrong somewhere...
It may be those Single Quotes, because I have generated a title="chapter # and name" many times. I did this with Sigil
theducks is offline   Reply With Quote
Old 08-28-2019, 07:55 PM   #5
mjcatt
Junior Member
mjcatt began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
Quote:
Originally Posted by theducks View Post
It may be those Single Quotes, because I have generated a title="chapter # and name" many times. I did this with Sigil
My bad. I just checked one of the example books again and it does use double quotes, not single quotes as I mistakenly wrote in my post. It turns out that it doesn't matter if they are single or double quotes - I get the same generated TOC either way.

I continue to look for any settings that would affect the TOC generator but don't see any. In editor preferences I did a 'restore all defaults' just to be sure - no changes.
mjcatt is offline   Reply With Quote
Old 08-28-2019, 09:15 PM   #6
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,953
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It always uses the text in the tag in preference to the title or any other attribute. You can try using

//h:h2/@title

however I dont recall if it works with XPath that returns attributes insetead of tags.
kovidgoyal is online now   Reply With Quote
Old 08-28-2019, 11:34 PM   #7
mjcatt
Junior Member
mjcatt began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
Thanks Kovid. I had tried that earlier but no items were returned. I am continuing to dabble further with xpath. If all else fails I can resort to (inelegant) brute force HTML changes to the book via somewhat involved search/replace expressions in the editor.
mjcatt is offline   Reply With Quote
Old 08-29-2019, 01:49 AM   #8
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,953
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Nothing super involved, just replace <h2(.+?)>.+< with <h2\1><

then generate the toc, copy it out and revert the changes and paste the toc back.
kovidgoyal is online now   Reply With Quote
Old 08-29-2019, 01:24 PM   #9
mjcatt
Junior Member
mjcatt began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
Yes, something like that will work and will be the simplest approach. Thanks.
mjcatt is offline   Reply With Quote
Reply

Tags
toc creation, xpath


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate ToC from XPath Problem marvinn Editor 2 09-04-2018 10:21 PM
inline ToC via XPath? chaot Sigil 22 03-20-2017 10:06 PM
TOC from XPath Paulie_D Editor 5 05-26-2015 02:55 PM
Nested TOC / Xpath question halfgone Conversion 0 02-13-2012 07:46 PM
Xpath TOC Expression Agama Calibre 2 07-12-2010 02:24 AM


All times are GMT -4. The time now is 09:50 AM.


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