08-28-2019, 04:11 PM | #1 |
Junior Member
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! |
08-28-2019, 04:56 PM | #2 | |
Well trained by Cats
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:
|
|
08-28-2019, 06:16 PM | #3 | |
Junior Member
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
|
Quote:
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... |
|
08-28-2019, 07:09 PM | #4 | |
Well trained by Cats
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:
|
|
08-28-2019, 07:55 PM | #5 | |
Junior Member
Posts: 6
Karma: 10
Join Date: Jul 2018
Device: kindle voyage, Moon+Reader Pro
|
Quote:
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. |
|
08-28-2019, 09:15 PM | #6 |
creator of calibre
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. |
08-28-2019, 11:34 PM | #7 |
Junior Member
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.
|
08-29-2019, 01:49 AM | #8 |
creator of calibre
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. |
08-29-2019, 01:24 PM | #9 |
Junior Member
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.
|
Tags |
toc creation, xpath |
|
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 |