<p:declare-stepxmlns:p="http://www.w3.org/ns/xproc"xmlns:px="http://www.daisy.org/ns/pipeline/xproc"xmlns:pf="http://www.daisy.org/ns/pipeline/functions"xmlns:cx="http://xmlcalabash.com/ns/extensions"xmlns:c="http://www.w3.org/ns/xproc-step"xmlns:d="http://www.daisy.org/ns/pipeline/data"xmlns:xs="http://www.w3.org/2001/XMLSchema"version="1.0"name="main"type="px:dtbook-to-epub3.script"px:input-filesets="dtbook"px:output-filesets="epub3"exclude-inline-prefixes="#all">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h1px:role="name">DTBook to EPUB 3</h1><ppx:role="desc">Converts multiple dtbooks to EPUB 3 format</p>
<apx:role="homepage"href="http://daisy.github.io/pipeline/Get-Help/User-Guide/Scripts/dtbook-to-epub3/">
Online documentation
</a>
</p:documentation>
<p:inputport="source"primary="true"sequence="true"px:media-type="application/x-dtbook+xml">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">DTBook file(s)</h2><ppx:role="desc">One or more DTBook files to be transformed. In the case of multiple files, a merge will be performed.</p>
</p:documentation>
</p:input><p:outputport="tts-log"sequence="true"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">TTS log</h2><ppx:role="desc"xml:space="preserve">Log file with information about text-to-speech process.
Can be enabled with the "Include TTS log" option or the
[`org.daisy.pipeline.tts.log`](http://daisy.github.io/pipeline/Get-Help/User-Guide/Text-To-Speech/#common-settings)
property.
</p>
</p:documentation>
<p:pipestep="result"port="tts-log"/>
</p:output><p:optionname="language"select="''"required="false"px:type="string"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Language code</h2><ppx:role="desc">Language code of the input document.</p>
</p:documentation>
</p:option><p:optionname="result"required="true"px:output="result"px:type="anyDirURI"px:media-type="text">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">EPUB</h2><ppx:role="desc">The resulting EPUB 3 publication.</p>
</p:documentation>
</p:option><p:optionname="validation"select="'abort'"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: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"primary="true">
</p:output><p:optionname="nimas"select="'false'"required="false"px:type="boolean"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">NIMAS input</h2><ppx:role="desc">Whether the input DTBook is a NIMAS 1.1-conformant XML content file.</p>
</p:documentation>
</p:option><p:inputport="tts-config"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:optionxmlns:_="dtbook"name="_:chunk-size"select="'-1'"required="false"px:type="integer"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Chunk size</h2><ppx:role="desc"xml:space="preserve">The maximum size of HTML files in kB. Specify "-1" for no maximum.
Top-level sections in the DTBook become separate HTML files in the resulting EPUB, and are further
split up if they exceed the given maximum size.</p>
</p:documentation>
</p:option><p:optionname="audio"select="'false'"required="false"px:type="boolean"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Enable text-to-speech</h2><ppx:role="desc">Whether to use a speech synthesizer to produce audio files.</p>
</p:documentation>
</p:option>
<p:importhref="convert.xpl">
<p:documentation>
px:dtbook-to-epub3
</p:documentation>
</p:import>
<p:importhref="http://www.daisy.org/pipeline/modules/fileset-utils/library.xpl">
<p:documentation>
px:fileset-add-entries
</p:documentation>
</p:import>
<p:importhref="http://www.daisy.org/pipeline/modules/dtbook-utils/library.xpl">
<p:documentation>
px:dtbook-load
</p:documentation>
</p:import>
<p:importhref="http://www.daisy.org/pipeline/modules/epub-utils/library.xpl">
<p:documentation>
px:epub3-store
</p:documentation>
</p:import>
<cx:importhref="http://www.daisy.org/pipeline/modules/file-utils/library.xsl"type="application/xslt+xml">
<p:documentation>
pf:normalize-uri
</p:documentation>
</cx:import>
<p:sink/>
<px:fileset-add-entriesmedia-type="application/x-dtbook+xml"name="dtbook">
<p:inputport="entries">
<p:pipestep="main"port="source"/>
</p:input>
</px:fileset-add-entries>
<px:dtbook-loadname="load"px:progress=".1"px:message="Loading DTBook">
<p:inputport="source.in-memory">
<p:pipestep="dtbook"port="result.in-memory"/>
</p:input>
<p:with-optionname="validation"select="not($validation='off')"/>
<p:with-optionname="nimas"select="$nimas='true'"/>
</px:dtbook-load>
<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 input contains an invalid DTBook file. See validation report for more info."px:message-severity="ERROR"/>
</p:when>
<p:otherwise>
<p:identitypx:message="The input contains an invalid DTBook file. 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="result"px:progress=".9">
<p:whentest="/d:validation-status[@result='error'] and $validation='abort'">
<p:outputport="status"primary="true"/>
<p:outputport="tts-log"sequence="true">
<p:empty/>
</p:output>
<p:identity/>
</p:when>
<p:otherwise>
<p:outputport="status"primary="true"/>
<p:outputport="tts-log"sequence="true">
<p:pipestep="convert-and-store"port="tts-log"/>
</p:output>
<p:variablename="dtbook-is-valid"cx:as="xs:boolean"select="not($validation='off') and exists(/d:validation-status[@result='ok'])"/>
<p:sink/>
<p:split-sequencetest="position()=1"initial-only="true">
<p:inputport="source">
<p:pipestep="main"port="source"/>
</p:input>
</p:split-sequence>
<p:groupname="convert-and-store"px:progress="1">
<p:outputport="status"primary="true"/>
<p:outputport="tts-log"sequence="true">
<p:pipestep="convert"port="tts-log"/>
</p:output>
<p:variablename="dtbook-uri"select="base-uri(/)"/>
<p:variablename="output-name"select="replace(replace($dtbook-uri,'^.*/([^/]+)$','$1'),'\.[^\.]*$','')"/>
<p:variablename="output-dir-uri"select="pf:normalize-uri(concat($result,'/'))"/>
<p:variablename="epub-file-uri"select="concat($output-dir-uri,$output-name,'.epub')"/>
<p:sink/>
<px:dtbook-to-epub3name="convert"px:progress="8/9">
<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: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,$dtbook-uri), ' ')"/>
<p:with-optionname="lexicon"select="for $l in tokenize($lexicon,'\s+')[not(.='')] return resolve-uri($l,$dtbook-uri)"/>
<p:with-optionname="audio"select="$audio"/>
<p:with-optionname="audio-file-type"select="$audio-file-type"/>
<p:with-optionname="language"select="$language"/>
<p:with-optionname="validation"select="$validation"/>
<p:with-optionname="dtbook-is-valid"select="$dtbook-is-valid"/>
<p:with-optionname="nimas"select="$nimas='true'"/>
<p:with-optionxmlns:_="dtbook"name="chunk-size"select="$_:chunk-size"/>
<p:with-optionname="output-name"select="$output-name"/>
<p:with-optionname="output-dir"select="$output-dir-uri"/>
<p:with-optionname="temp-dir"select="$temp-dir"/>
</px:dtbook-to-epub3>
<px:epub3-storename="store"px:progress="1/9"px:message="Storing EPUB 3">
<p:inputport="in-memory.in">
<p:pipestep="convert"port="result.in-memory"/>
</p:input>
<p:with-optionname="href"select="$epub-file-uri"/>
</px:epub3-store>
<p:identitycx:depends-on="store">
<p:inputport="source">
<p:pipestep="convert"port="status"/>
</p:input>
</p:identity>
</p:group>
</p:otherwise>
</p:choose>
</p:declare-step>