<p:declare-stepxmlns:p="http://www.w3.org/ns/xproc"xmlns:px="http://www.daisy.org/ns/pipeline/xproc"xmlns:cx="http://xmlcalabash.com/ns/extensions"xmlns:d="http://www.daisy.org/ns/pipeline/data"version="1.0"type="px:epub-to-daisy.script"name="main">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h1px:role="name">EPUB to DAISY</h1><ppx:role="desc">Transforms an EPUB 2 or EPUB 3 publication into DAISY 2.02 and DAISY 3.</p>
<apx:role="homepage"href="http://daisy.github.io/pipeline/Get-Help/User-Guide/Scripts/epub-to-daisy/">
Online documentation
</a>
</p:documentation>
<p:optionname="source"required="true"px:type="anyFileURI"px:media-type="application/epub+zip application/oebps-package+xml">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">EPUB Publication</h2><ppx:role="desc"xml:space="preserve">The EPUB 2 or EPUB 3 you want to transform.
You may alternatively use the "mimetype" document if your input is a unzipped/"exploded" version of an EPUB.</p>
</p:documentation>
</p:option><p:optionname="validation"select="'off'"required="false"><p:pipeinfo><px:type>
<choicexmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0">
<value>off</value>
<a:documentationxml:lang="en">No validation</a:documentation>
<value>report</value>
<a:documentationxml:lang="en">Report validation issues</a:documentation>
<value>abort</value>
<a:documentationxml:lang="en">Abort on validation issues</a:documentation>
</choice>
</px:type></p:pipeinfo><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Validation</h2><ppx:role="desc">Whether to abort on validation issues.</p>
</p:documentation>
</p:option><p:optionname="tts"required="false"select="'default'">
<p:pipeinfo>
<px:type>
<choicexmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0">
<value>true</value>
<a:documentationxml:lang="en">Yes</a:documentation>
<value>false</value>
<a:documentationxml:lang="en">No</a:documentation>
<value>default</value>
<a:documentationxml:lang="en">If publication has no media overlays yet</a:documentation>
</choice>
</px:type>
</p:pipeinfo>
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Perform text-to-speech</h2><ppx:role="desc"xml:space="preserve">Whether to use a speech synthesizer to produce media overlays.
This will remove any existing media overlays in the EPUB.</p>
</p:documentation>
</p:option><p:inputport="tts-config"primary="false"px:media-type="application/vnd.pipeline.tts-config+xml"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Text-to-speech configuration file</h2><ppx:role="desc"xml:space="preserve">Configuration file for text-to-speech.
[More details on the configuration file format](http://daisy.github.io/pipeline/Get-Help/User-Guide/Text-To-Speech/).</p>
</p:documentation>
<p:inline><d:config/></p:inline>
</p:input><p:optionxmlns:_="tts"name="_:stylesheet"select="''"required="false"px:type="anyURI"px:sequence="true"px:separator=" "px:media-type="text/css text/x-scss"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Style sheets</h2><ppx:role="desc"xml:space="preserve">A list of CSS style sheets to take into account.
Must be a space separated list of URIs, absolute or relative to the input.
Style sheets specified through this option are called "[user style
sheets](https://www.w3.org/TR/CSS2/cascade.html#cascade)". Style sheets can also be attached to the
source document. These are referred to as "[author style
sheets](https://www.w3.org/TR/CSS2/cascade.html#cascade)". They can be linked (using an
['xml-stylesheet' processing instruction](https://www.w3.org/TR/xml-stylesheet) or a ['link'
element](https://www.w3.org/Style/styling-XML#External)), embedded (using a ['style'
element](https://www.w3.org/Style/styling-XML#Embedded)) and/or inlined (using '[style'
attributes](https://www.w3.org/TR/css-style-attr/)). Only author styles that apply to
"[speech](https://www.w3.org/TR/CSS2/aural.html)" media are taken into account.
All style sheets are applied at once, but the order in which they are specified has an influence on
the [cascading order](https://www.w3.org/TR/CSS2/cascade.html#cascading-order). Author styles take
precedence over user styles.
</p>
</p:documentation>
</p:option><p:optionname="lexicon"select="p:system-property('d:org.daisy.pipeline.tts.default-lexicon')"required="false"px:type="anyURI"px:sequence="true"px:separator=" "px:media-type="application/pls+xml"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Lexicons</h2><ppx:role="desc"xml:space="preserve">A list of PLS lexicons to take into account.
Must be a space separated list of URIs, absolute or relative to the input.
Style sheets can also be attached to the source document, using an ['xml-stylesheet' processing
instruction](https://www.w3.org/TR/xml-stylesheet) or a ['link'
element](http://kb.daisy.org/publishing/docs/text-to-speech/pls.html#ex-07).
</p>
</p:documentation>
</p:option><p:optionname="epub3"required="true"px:output="result"px:type="anyDirURI">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Intermediary EPUB 3 with media-overlays</h2>
<p>Note that the conversion may fail but still output a EPUB 3 document.</p>
</p:documentation>
</p:option><p:optionname="daisy202"required="true"px:output="result"px:type="anyDirURI">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">DAISY 2.02</h2>
</p:documentation>
</p:option><p:optionname="daisy3"required="true"px:output="result"px:type="anyDirURI">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">DAISY 3</h2>
</p:documentation>
</p:option><p:outputport="validation-report"sequence="true"px:media-type="application/vnd.pipeline.report+xml"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Validation reports</h2>
</p:documentation>
<p:pipestep="load"port="validation-report"/>
</p:output><p:outputport="status"px:media-type="application/vnd.pipeline.status+xml">
<p:pipestep="status"port="result"/>
</p:output>
<p:importhref="http://www.daisy.org/pipeline/modules/epub-utils/library.xpl">
<p:documentation>
px:epub-load
</p:documentation>
</p:import>
<p:importhref="http://www.daisy.org/pipeline/modules/fileset-utils/library.xpl">
<p:documentation>
px:fileset-store
px:fileset-delete
</p:documentation>
</p:import>
<p:importhref="epub-to-daisy.xpl">
<p:documentation>
px:epub-to-daisy
</p:documentation>
</p:import>
<px:epub-loadname="load"px:message="Loading EPUB"px:progress="1/20">
<p:with-optionname="href"select="$source"/>
<p:with-optionname="validation"select="not($validation='off')"/>
<p:with-optionname="temp-dir"select="$temp-dir"/>
</px:epub-load>
<p:sink/>
<p:identity>
<p:inputport="source">
<p:pipestep="load"port="validation-status"/>
</p:input>
</p:identity>
<p:choose>
<p:whentest="/d:validation-status[@result='error']">
<p:choose>
<p:whentest="$validation='abort'">
<p:identitypx:message="The EPUB input is invalid. See validation report for more info."px:message-severity="ERROR"/>
</p:when>
<p:otherwise>
<p:identitypx:message="The EPUB input is invalid. See validation report for more info."px:message-severity="WARN"/>
</p:otherwise>
</p:choose>
</p:when>
<p:otherwise>
<p:identity/>
</p:otherwise>
</p:choose>
<p:choosename="status"px:progress="19/20">
<p:whentest="/d:validation-status[@result='error'] and $validation='abort'">
<p:outputport="result"/>
<p:identity/>
</p:when>
<p:otherwise>
<p:outputport="result"/>
<px:epub-to-daisyname="convert"px:message="Converting to DAISY"px:progress="15/19">
<p:inputport="source.fileset">
<p:pipestep="load"port="result.fileset"/>
</p:input>
<p:inputport="source.in-memory">
<p:pipestep="load"port="result.in-memory"/>
</p:input>
<p:with-optionname="epub3-output-dir"select="$epub3"/>
<p:with-optionname="daisy202-output-dir"select="$daisy202"/>
<p:with-optionname="daisy3-output-dir"select="$daisy3"/>
<p:with-optionname="tts"select="$tts"/>
<p:inputport="tts-config">
<p:pipestep="main"port="tts-config"/>
</p:input>
<p:with-optionxmlns:_="tts"name="stylesheet"select="string-join( for $s in tokenize($_:stylesheet,'\s+')[not(.='')] return resolve-uri($s,$source), ' ')"/>
<p:with-optionname="lexicon"select="for $l in tokenize($lexicon,'\s+')[not(.='')] return resolve-uri($l,$source)"/>
<p:with-optionname="temp-dir"select="$temp-dir"/>
</px:epub-to-daisy>
<px:fileset-storename="store-epub3"px:message="Storing intermediary EPUB 3"px:progress="1/19">
<p:inputport="fileset.in">
<p:pipestep="convert"port="epub3.fileset"/>
</p:input>
<p:inputport="in-memory.in">
<p:pipestep="convert"port="epub3.in-memory"/>
</p:input>
</px:fileset-store>
<p:choosename="store-daisy202"px:progress="1/19">
<p:xpath-context>
<p:pipestep="convert"port="daisy202.fileset"/>
</p:xpath-context>
<p:whentest="//d:file">
<p:outputport="result">
<p:pipestep="store"port="fileset.out"/>
</p:output>
<px:fileset-storename="store"px:progress="1"px:message="Storing DAISY 2.02">
<p:inputport="fileset.in">
<p:pipestep="convert"port="daisy202.fileset"/>
</p:input>
<p:inputport="in-memory.in">
<p:pipestep="convert"port="daisy202.in-memory"/>
</p:input>
</px:fileset-store>
</p:when>
<p:otherwise>
<p:outputport="result"/>
<p:identity>
<p:inputport="source">
<p:pipestep="convert"port="daisy202.fileset"/>
</p:input>
</p:identity>
</p:otherwise>
</p:choose>
<p:choosename="store-daisy3"px:progress="1/19">
<p:xpath-context>
<p:pipestep="convert"port="daisy3.fileset"/>
</p:xpath-context>
<p:whentest="//d:file">
<p:outputport="result">
<p:pipestep="store"port="fileset.out"/>
</p:output>
<px:fileset-storename="store"px:progress="1"px:message="Storing DAISY 3">
<p:inputport="fileset.in">
<p:pipestep="convert"port="daisy3.fileset"/>
</p:input>
<p:inputport="in-memory.in">
<p:pipestep="convert"port="daisy3.in-memory"/>
</p:input>
</px:fileset-store>
</p:when>
<p:otherwise>
<p:outputport="result"/>
<p:identity>
<p:inputport="source">
<p:pipestep="convert"port="daisy3.fileset"/>
</p:input>
</p:identity>
</p:otherwise>
</p:choose>
<p:identitycx:depends-on="store-epub3">
<p:inputport="source">
<p:pipestep="convert"port="temp-audio-files"/>
</p:input>
</p:identity>
<p:identitycx:depends-on="store-daisy3"/>
<px:fileset-deletecx:depends-on="store-daisy202"name="delete-temp-files"px:progress="1/19"px:message="Cleaning up temporary files"/>
<p:identitycx:depends-on="delete-temp-files">
<p:inputport="source">
<p:inline><d:validation-statusresult="ok"/></p:inline>
</p:input>
</p:identity>
</p:otherwise>
</p:choose>
</p:declare-step>