[epub] Reorder playorder in toc.ncx

Are you missing a feature? Request it's implementation here.
rustic
Posts: 7

[epub] Reorder playorder in toc.ncx

Sun Jun 12, 2011 10:57 pm

If I decide to add a navpoint element in toc.ncx at the beginning of an existing toc.ncx in navmap, there is no way to reorder playOrder number but by hand. That could be really tedious if there are many navpoint elements.

Code: Select all

    <navPoint id="navPoint-1" playOrder="1">
      <navLabel>
        <text>1</text>
      </navLabel>
      <content src="Text/Section0002.xhtml"/>
    </navPoint>
    <navPoint id="navPoint-1" playOrder="1">
      <navLabel>
        <text>2</text>
      </navLabel>
      <content src="Text/Section0003.xhtml"/>
    </navPoint>
george
Site Admin
Posts: 2100

Re: [epub] Reorder playorder in toc.ncx

Tue Jun 14, 2011 2:33 pm

You can pass the NCX file though a stylesheet that assigns playOrder sequentially, like the fixPlayorder.xsl below:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <!-- Recursive copy template -->   
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    <!-- Always compute a sequential value for playOrder -->
    <xsl:template match="@playOrder">
        <xsl:attribute name="playOrder"><xsl:number count="*[@playOrder]" level="any"/></xsl:attribute>
    </xsl:template>
</xsl:stylesheet>


Best Regards,
George
George Cristian Bina
rustic
Posts: 7

Re: [epub] Reorder playorder in toc.ncx

Tue Jun 14, 2011 8:15 pm

It's working and in a blink of an eye :wink: XSLT is very powerful indeed. Thank you for your help George.
newt
Posts: 38
Location: London

Re: [epub] Reorder playorder in toc.ncx

Mon Jun 20, 2011 5:22 pm

@George, that will fail when the NCX file contains the same path twice. We often do that when we have a book divided into parts. There is nothing in the content to indicate the path but we want some indication in the navigation:

Code: Select all

<navMap>
   <navPoint id="chapter01" playOrder="1">

    <navLabel><text>Ready in 30 or less</text></navLabel>
    <content src="Chapter01.html"/>

    <navPoint id="chapter01a" playOrder="1">
       <navLabel><text>Thai red salmon curry</text></navLabel>
      <content src="Chapter01.html"/>
    </navPoint>

    <navPoint id="chapter01b" playOrder="2">
      <navLabel><text>Oven-baked Thai chicken rice</text></navLabel>
      <content src="Chapter01.html#chapter01b"/>
    </navPoint>

  </navPoint>

  <navPoint id="chapter02" playOrder="3">

    <navLabel><text>Light and lovely</text></navLabel>
    <content src="Chapter02.html"/>

    <navPoint id="chapter02a" playOrder="3">
      <navLabel><text>New potato and mince curry</text></navLabel>
      <content src="Chapter02.html"/>
    </navPoint>

    <navPoint id="chapter02b" playOrder="4">
      <navLabel><text>Easy-peasy lentil curry</text></navLabel>
      <content src="Chapter02.html#chapter02b"/>
    </navPoint>

  </navPoint>
</navMap>


You script will 'correct' that to wrong :)
I just put in a feature request for the current archive name as an editor variable to let me do something very like this!


nic
Director, Corbas Consulting
XML and eBook consultancy and training
george
Site Admin
Posts: 2100

Re: [epub] Reorder playorder in toc.ncx

Tue Jun 21, 2011 10:21 am

In that case the following XSLT 2.0 stylesheet will provide the correct values:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
    version="2.0">
   
    <xsl:variable name="paths"
        select="distinct-values(//ncx:content/normalize-space(@src))"/>
       
    <!-- Recursive copy template -->   
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@playOrder">
        <xsl:attribute name="playOrder">
            <xsl:value-of
                select="index-of($paths, parent::*/ncx:content/@src)"/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>


Regards,
George
George Cristian Bina
virtual_ink
Posts: 2

Re: [epub] Reorder playorder in toc.ncx

Wed Jun 29, 2011 7:31 am

I'm a newbie to epub creation and found this post in google while looking for a solution to the same problem. Some of our books have seventy chapters, and I don't want to rename them all by hand once I edit one element of the toc.

While I don't use oxygen as yet (I have heard of if it in some training videos I'm watching), I'm wondering if I could still use the above method as a fix? Or any other? I'm outputting my epubs from InDesign, then editing with a combination of TextWrangler and Sigil (and lots of trial and error!).

If you have the patience, could you please provide a complete novices' guide in step by step form for using this fix? I realise that's probably a big ask, so no pressure!
george
Site Admin
Posts: 2100

Re: [epub] Reorder playorder in toc.ncx

Wed Jun 29, 2011 12:55 pm

I am afraid you want something else. This stylesheet fixes the values for the playOrder attribute, it does not fix broken names. oXygen having EpubChek validation integrated will show you the broken links, if any, and you will be able to use oXygen to edit the files inside an EPUB to correct these problems.

Best Regards,
George
George Cristian Bina
virtual_ink
Posts: 2

Re: [epub] Reorder playorder in toc.ncx

Thu Jun 30, 2011 2:21 am

Thanks for the response George. I might have made my post unclear. To clarify, I want something that fixes the playOrder attribute.

Eg, if I change playOrder="2" to playOrder="4" (manually), I want something that will rename all the other playOrder #s in relation to this.
george
Site Admin
Posts: 2100

Re: [epub] Reorder playorder in toc.ncx

Thu Jun 30, 2011 9:49 am

The solution presented here takes a TOC file and it adds playOrder values in their natural/document order. It does not take into account any of the existing values. All you need is to apply the XSLT transformation on a NCX file with broken playOrder values and you will get as result the NCX file with the playOrder values fixed.

Best Regards,
George
George Cristian Bina
sofarocker
Posts: 5

Re: [epub] Reorder playorder in toc.ncx

Mon Jun 01, 2015 5:27 pm

Hi, i`am newbi and try to automate my ncx-file with the XSLT-2.0 stylesheet but i want work.

How can i use this XSLT 2.0 stylesheet in my epub-folder with oxygen. when i try, the stylesheet makes me just two entries. i was appreciated when somebody gives me a step by step introduction.
Costin
Posts: 437

Re: [epub] Reorder playorder in toc.ncx

Tue Jun 02, 2015 4:06 pm

Hi sofarocker,

First, you should just open the .ncx file from your Epub, then configure a transformation scenario which you could further apply to transform the document.

To set up the scenario you can either:
- open the ncx file and look in the "Transformation Scenarios" view (Window > Show View > Transformation Scenarios)
- open the ncx file and from the main menu invoke Document -> Transformation -> "Configure Transformation Scenario(s)" (there's a corresponding button in the toolbar)

In the "Configure Transformation Scenario(s)" dialog press "New" and select "XML transformation with XSLT" to create a new scenario:
1. Give it an appropriate name
2. Leave the "XML URL" field to its default(${currentFileURL})
3. In the XSL URL field browse for your stylesheet.
4. As you specified you have an XSLT 2.0 stylesheet choose from the transformer combo Saxon-PE or Saxon-EE.
5. You can further tune the "Output". Please note that the "Save as" field must refer a single file, NOT an output directory. Use the editor variables to compose a generic name instead of a fixed one.
e.g in the "Save as" field you can specify: ${cfd}/${cfn}-out.xml which translates into <current-file-directory>/<current-filename>-out.xml
6. Press OK in the editing dialog and "Save and close".

Going further, you can apply the transformation scenario you have just created by going into menu Document > Transformation > Apply Transformation Scenario(s), or by using the related shortcut button in the toolbar.

I hope this helps.

Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support

Return to “Feature Request”

Who is online

Users browsing this forum: No registered users and 1 guest