<p:declare-step xmlns: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:documentation xmlns="http://www.w3.org/1999/xhtml"> <h1 px:role="name">DTBook to EPUB 3</h1> <p px:role="desc">Converts multiple dtbooks to EPUB 3 format</p> <a px:role="homepage" href="http://daisy.github.io/pipeline/Get-Help/User-Guide/Scripts/dtbook-to-epub3/"> Online documentation </a> </p:documentation> <p:input port="source" primary="true" sequence="true" px:media-type="application/x-dtbook+xml"> <p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">DTBook file(s)</h2> <p px: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:output port="tts-log" sequence="true"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">TTS log</h2> <p px:role="desc">Log file with information about text-to-speech process.</p> </p:documentation> <p:pipe step="result" port="tts-log"/> </p:output> <p:serialization port="tts-log" indent="true" omit-xml-declaration="false"/> <p:option xmlns:_="tts" name="_:stylesheet" select="''" required="false" px:type="anyURI" px:sequence="true" px:separator=" " px:media-type="text/css text/x-scss"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Style sheets</h2>

A;['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 px: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:option name="stylesheet-parameters" select="'()'" required="false" px:type="stylesheet-parameters"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Style sheet parameters</h2> <p px:role="desc" xml:space="preserve">A list of parameters passed to the style sheets. Style sheets, whether they're user style sheets (specified with the "Style sheets" option) or author style sheets (associated with the source), may have parameters (Sass variables). This option, which takes a comma-separated list of key-value pairs enclosed in parenthesis, can be used to set these variables. For example, if a style sheet uses the Sass variable "foo": ~~~sass @if $foo { /* some style that should only be enabled when "foo" is truthy */ } ~~~ you can control that variable with the following parameters list: `(foo:true)`.</p> </p:documentation> </p:option> <p:option name="language" select="''" required="false" px:type="string"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Language code</h2> <p px:role="desc">Language code of the input document.</p> </p:documentation> </p:option> <p:option name="result" required="true" px:output="result" px:type="anyDirURI" px:media-type="text"> <p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">EPUB</h2> <p px:role="desc">The resulting EPUB 3 publication.</p> </p:documentation> </p:option> <p:option name="validation" select="'abort'" required="false"><p:pipeinfo> <px:type> <choice xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"> <value>off</value> <a:documentation xml:lang="en">No validation</a:documentation> <value>report</value> <a:documentation xml:lang="en">Report validation issues</a:documentation> <value>abort</value> <a:documentation xml:lang="en">Abort on validation issues</a:documentation> </choice> </px:type></p:pipeinfo><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Validation</h2> <p px:role="desc">Whether to abort on validation issues.</p> </p:documentation> </p:option> <p:output port="validation-report" sequence="true" px:media-type="application/vnd.pipeline.report+xml"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Validation reports</h2> </p:documentation> <p:pipe step="load" port="validation-report"/> </p:output> <p:output port="status" px:media-type="application/vnd.pipeline.status+xml" primary="true"> </p:output> <p:option name="nimas" select="'false'" required="false" px:type="boolean"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">NIMAS input</h2> <p px:role="desc">Whether the input DTBook is a NIMAS 1.1-conformant XML content file.</p> </p:documentation> </p:option> <p:input port="tts-config" px:media-type="application/vnd.pipeline.tts-config+xml"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Text-to-speech configuration file</h2> <p px: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:option name="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:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Lexicons</h2> <p px: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. Lexicons can also be attached to the source document, using a ['link' element](http://kb.daisy.org/publishing/docs/text-to-speech/pls.html#ex-07). PLS lexicons allow you to define custom pronunciations of words. It is meant to help TTS processors deal with ambiguous abbreviations and pronunciation of proper names. When a word is defined in a lexicon, the processor will use the provided pronunciation instead of the default rendering. The syntax of a PLS lexicon is defined in [Pronunciation Lexicon Specification (PLS) Version 1.0](https://www.w3.org/TR/pronunciation-lexicon), extended with regular expression matching. To enable regular expression matching, add the "regex" attribute, as follows: ~~~xml <lexicon xmlns="http://www.w3.org/2005/01/pronunciation-lexicon" version="1.0" alphabet="ipa" xml:lang="en"> <lexeme regex="true"> <grapheme>([0-9]+)-([0-9]+)</grapheme> <alias>between $1 and $2</alias> </lexeme> </lexicon> ~~~ The regex feature works only with alias-based substitutions. The regex syntax used is that from [XQuery 1.0 and XPath 2.0](https://www.w3.org/TR/xpath-functions/#regex-syntax). Whether or not the regex attribute is set to "true", the grapheme matching can be made more accurate by specifying the "positive-lookahead" and "negative-lookahead" attributes: ~~~xml <lexicon version="1.0" xmlns="http://www.w3.org/2005/01/pronunciation-lexicon" alphabet="ipa" xml:lang="en"> <lexeme> <grapheme positive-lookahead="[ ]+is">SB</grapheme> <alias>somebody</alias> </lexeme> <lexeme> <grapheme>SB</grapheme> <alias>should be</alias> </lexeme> <lexeme xml:lang="fr"> <grapheme positive-lookahead="[ ]+[cC]ity">boston</grapheme> <phoneme>bɔstøn</phoneme> </lexeme> </lexicon> ~~~ Graphemes with "positive-lookahead" will match if the beginning of what follows matches the "position-lookahead" pattern. Graphemes with "negative-lookahead" will match if the beginning of what follows does not match the "negative-lookahead" pattern. The lookaheads are case-sensitive while the grapheme contents are not. The lexemes are matched in this order: 1. Graphemes with regex="false" come first, no matter if there is a lookahead or not; 2. then come graphemes with regex="true" and no lookahead; 3. then graphemes with regex="true" and one or two lookaheads. Within these categories, lexemes are matched in the same order as they appear in the lexicons.</p> </p:documentation> </p:option> <p:option xmlns:_="dtbook" name="_:chunk-size" select="'-1'" required="false" px:type="integer"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Chunk size</h2> <p px: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:option name="audio" select="'false'" required="false" px:type="boolean"><p:documentation xmlns="http://www.w3.org/1999/xhtml"> <h2 px:role="name">Enable text-to-speech</h2> <p px:role="desc">Whether to use a speech synthesizer to produce audio files.</p> </p:documentation> </p:option> <p:import href="convert.xpl"> <p:documentation> px:dtbook-to-epub3 </p:documentation> </p:import> <p:import href="http://www.daisy.org/pipeline/modules/fileset-utils/library.xpl"> <p:documentation> px:fileset-add-entries </p:documentation> </p:import> <p:import href="http://www.daisy.org/pipeline/modules/dtbook-utils/library.xpl"> <p:documentation> px:dtbook-load </p:documentation> </p:import> <p:import href="http://www.daisy.org/pipeline/modules/epub-utils/library.xpl"> <p:documentation> px:epub3-store </p:documentation> </p:import> <cx:import href="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-entries media-type="application/x-dtbook+xml" name="dtbook"> <p:input port="entries"> <p:pipe step="main" port="source"/> </p:input> </px:fileset-add-entries> <px:dtbook-load name="load" px:progress=".1" px:message="Loading DTBook"> <p:input port="source.in-memory"> <p:pipe step="dtbook" port="result.in-memory"/> </p:input> <p:with-option name="validation" select="not($validation='off')"/> <p:with-option name="nimas" select="$nimas='true'"/> </px:dtbook-load> <p:identity> <p:input port="source"> <p:pipe step="load" port="validation-status"/> </p:input> </p:identity> <p:choose> <p:when test="/d:validation-status[@result='error']"> <p:choose> <p:when test="$validation='abort'"> <p:identity px:message="The input contains an invalid DTBook file. See validation report for more info." px:message-severity="ERROR"/> </p:when> <p:otherwise> <p:identity px: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:choose name="result" px:progress=".9"> <p:when test="/d:validation-status[@result='error'] and $validation='abort'"> <p:output port="status" primary="true"/> <p:output port="tts-log" sequence="true"> <p:empty/> </p:output> <p:identity/> </p:when> <p:otherwise> <p:output port="status" primary="true"/> <p:output port="tts-log" sequence="true"> <p:pipe step="convert-and-store" port="tts-log"/> </p:output> <p:variable name="dtbook-is-valid" cx:as="xs:boolean" select="not($validation='off') and exists(/d:validation-status[@result='ok'])"/> <p:sink/> <p:split-sequence test="position()=1" initial-only="true"> <p:input port="source"> <p:pipe step="main" port="source"/> </p:input> </p:split-sequence> <p:group name="convert-and-store" px:progress="1"> <p:output port="status" primary="true"/> <p:output port="tts-log" sequence="true"> <p:pipe step="convert" port="tts-log"/> </p:output> <p:variable name="dtbook-uri" select="base-uri(/)"/> <p:variable name="output-name" select="replace(replace($dtbook-uri,'^.*/([^/]+)$','$1'),'\.[^\.]*$','')"/> <p:variable name="output-dir-uri" select="pf:normalize-uri(concat($result,'/'))"/> <p:variable name="epub-file-uri" select="concat($output-dir-uri,$output-name,'.epub')"/> <p:sink/> <px:dtbook-to-epub3 name="convert" px:progress="8/9"> <p:input port="source.fileset"> <p:pipe step="load" port="result.fileset"/> </p:input> <p:input port="source.in-memory"> <p:pipe step="load" port="result.in-memory"/> </p:input> <p:input port="tts-config"> <p:pipe step="main" port="tts-config"/> </p:input> <p:with-option xmlns:_="tts" name="stylesheet" select="string-join( for $s in tokenize($_:stylesheet,'\s+')[not(.='')] return resolve-uri($s,$dtbook-uri), ' ')"/> <p:with-option name="stylesheet-parameters" select="$stylesheet-parameters"/> <p:with-option name="lexicon" select="for $l in tokenize($lexicon,'\s+')[not(.='')] return resolve-uri($l,$dtbook-uri)"/> <p:with-option name="audio" select="$audio"/> <p:with-option name="audio-file-type" select="$audio-file-type"/> <p:with-option name="language" select="$language"/> <p:with-option name="validation" select="$validation"/> <p:with-option name="dtbook-is-valid" select="$dtbook-is-valid"/> <p:with-option name="nimas" select="$nimas='true'"/> <p:with-option xmlns:_="dtbook" name="chunk-size" select="$_:chunk-size"/> <p:with-option name="output-name" select="$output-name"/> <p:with-option name="output-dir" select="concat($temp-dir,'epub3-unzipped/')"/> <p:with-option name="temp-dir" select="concat($temp-dir,'temp/')"/> </px:dtbook-to-epub3> <px:epub3-store name="store" px:progress="1/9" px:message="Storing EPUB 3"> <p:input port="in-memory.in"> <p:pipe step="convert" port="result.in-memory"/> </p:input> <p:with-option name="href" select="$epub-file-uri"/> </px:epub3-store> <p:identity cx:depends-on="store"> <p:input port="source"> <p:pipe step="convert" port="status"/> </p:input> </p:identity> </p:group> </p:otherwise> </p:choose> </p:declare-step>