<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:d="http://www.daisy.org/ns/pipeline/data"xmlns:xs="http://www.w3.org/2001/XMLSchema"version="1.0"type="px:dtbook-to-ebraille.script"px:input-filesets="dtbook"px:output-filesets="ebraille"exclude-inline-prefixes="#all"name="main">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h1px:role="name">DTBook to eBraille</h1><ppx:role="desc">Converts a DTBook to an eBraille publication</p>
<apx:role="homepage"href="http://daisy.github.io/pipeline/Get-Help/User-Guide/Scripts/dtbook-to-ebraille/">
Online documentation
</a>
</p:documentation>
<p:inputport="source"primary="true"px:media-type="application/x-dtbook+xml">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">DTBook</h2><ppx:role="desc">The 2005-3 DTBook or NIMAS file to be transformed.</p>
</p:documentation>
</p:input><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">eBraille</h2><ppx:role="desc">The resulting eBraille publication.</p>
</p:documentation>
</p:option><p:optionname="epub-package"required="false"select="false()"cx:as="xs:boolean">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Package in EPUB container</h2><ppx:role="desc"xml:space="preserve">Whether to package the eBraille publication in an EPUB 3-compatible container, or store it unzipped.
When packaged in an EPUB container, the output is a single file with
file extension `.ebrl`. When stored unzipped, the eBraille file set is
contained in a directory.</p>
</p:documentation>
</p:option><p:inputport="metadata"sequence="true"px:media-type="application/xml">
<p:empty/>
</p:input><p:optionname="attach-stylesheet"required="false"px:type="anyFileURI"select="''"px:sequence="true"px:separator=" "px:media-type="text/css text/x-scss">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Attach CSS style sheets</h2><ppx:role="desc"xml:space="preserve">CSS style sheet(s) to be attached with the HTML documents of the eBraille publication.
The style sheets are associated with each HTML file through `link`
elements. This script does not allow specifying `media` attributes on
the `link` elements. If media queries are needed, they must be
specified in the CSS itself, through `@media` and `@import` rules.
The style sheets are included as-is, and should therefore apply to
HTML, not DTBook.</p>
</p:documentation>
</p:option><p:optionname="braille-code"select="''"px:type="liblouis-table-query"required="false"><p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Braille code</h2><ppx:role="desc"xml:space="preserve">Braille code to be used for braille transcription.
If set, [braille transcription](http://daisy.github.io/pipeline/Get-Help/User-Guide/Braille/) is
done using the selected braille code. If left empty, the braille code is determined by the document
language. Note that braille transcription can also be controlled through CSS `@text-transform`
rules.</p>
</p:documentation>
</p:option><p:optionname="braille-translator-stylesheet"required="false"px:type="anyURI"select="''"px:sequence="true"px:separator=" "px:media-type="text/css text/x-scss">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Braille transcription style sheets</h2><ppx:role="desc"xml:space="preserve">A list of CSS/Sass style sheets to take into account for braille transcription.
Must be a space separated list of URIs, absolute or relative to the input.
Note that any CSS provided through this option will not end up in the eBraille publication. The
"Attach CSS style sheets" option should be used for that purpose.
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 "braille"
media are taken into account. Styles that do not influence the braille transcription, are ignored.
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.
Style sheets are interpreted according to [braille
CSS](http://braillespecs.github.io/braille-css) rules.
For info on how to use Sass (Syntactically Awesome StyleSheets) see the [Sass
manual](http://sass-lang.com/documentation/file.SASS_REFERENCE.html).</p>
</p:documentation>
</p:option><p:optionname="braille-translator-stylesheet-parameters"required="false"px:type="stylesheet-parameters"select="'()'">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Braille transcription style sheet parameters</h2><ppx:role="desc"xml:space="preserve">A list of parameters passed to the braille transcription style sheets.
Style sheets, whether they're user style sheets (specified with the "Braille transcription 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:optionname="validation"select="'report'"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:optionname="include-original-text"cx:as="xs:boolean"select="false()">
<p:documentationxmlns="http://www.w3.org/1999/xhtml">
<h2px:role="name">Include original text</h2><ppx:role="desc">Include the original text as a secondary rendition.</p>
</p:documentation>
</p:option>
<p:importhref="dtbook-to-ebraille.xpl">
<p:documentation>
px:dtbook-to-ebraille
</p:documentation>
</p:import>
<p:importhref="http://www.daisy.org/pipeline/modules/common-utils/library.xpl">
<p:documentation>
px:tokenize
</p:documentation>
</p:import>
<p:importhref="http://www.daisy.org/pipeline/modules/fileset-utils/library.xpl">
<p:documentation>
px:fileset-add-entry
px:fileset-add-entries
px:fileset-filter
px:fileset-copy
px:fileset-join
px:fileset-store
</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/css-utils/library.xpl">
<p:documentation>
px:css-to-fileset
</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:choosepx:progress=".9">
<p:whentest="/d:validation-status[@result='error'] and $validation='abort'">
<p:identity/>
</p:when>
<p:otherwise>
<p:variablename="dtbook-is-valid"cx:as="xs:boolean"select="not($validation='off') and exists(/d:validation-status[@result='ok'])"/>
<p:sink/>
<p:groupname="css">
<p:outputport="result"/>
<px:tokenizeregex="\s+">
<p:with-optionname="string"select="normalize-space($attach-stylesheet)"/>
</px:tokenize>
<p:for-each>
<p:variablename="href"select="string(.)"/>
<px:fileset-create>
<p:with-optionname="base"select="resolve-uri('./',$href)"/>
</px:fileset-create>
<px:fileset-add-entrymedia-type="text/css">
<p:with-optionname="href"select="$href"/>
<p:with-paramport="file-attributes"name="role"select="'stylesheet'"/>
</px:fileset-add-entry>
<px:css-to-fileset>
</px:css-to-fileset>
<px:fileset-copy>
<p:with-optionname="target"select="$temp-dir"/>
</px:fileset-copy>
</p:for-each>
<px:fileset-join/>
</p:group>
<p:sink/>
<p:identity>
<p:inputport="source">
<p:pipestep="main"port="source"/>
</p:input>
</p:identity>
<p:grouppx:progress="1">
<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:sink/>
<px:dtbook-to-ebraillename="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="css.fileset">
<p:pipestep="css"port="result"/>
</p:input>
<p:inputport="css.in-memory">
<p:empty/>
</p:input>
<p:with-optionname="braille-translator"select="$braille-code"/>
<p:with-optionname="braille-translator-stylesheet"select="string-join( for $s in tokenize($braille-translator-stylesheet,'\s+')[not(.='')] return resolve-uri($s,$dtbook-uri), ' ')"/>
<p:with-optionname="braille-translator-stylesheet-parameters"select="$braille-translator-stylesheet-parameters"/>
<p:with-optionname="dtbook-is-valid"select="$dtbook-is-valid"/>
<p:with-optionname="nimas"select="$nimas='true'"/>
<p:with-optionname="include-original-text"select="$include-original-text"/>
<p:with-optionname="output-dir"select="if ($epub-package) then concat($temp-dir,'ebraille-unzipped/') else concat($output-dir-uri,'/')"/>
<p:with-optionname="temp-dir"select="if ($epub-package) then concat($temp-dir,'temp/') else $temp-dir"/>
</px:dtbook-to-ebraille>
<p:choosename="store"px:progress="1/9">
<p:whentest="$epub-package"px:message="Storing in EPUB 3 package">
<px:epub3-storepx:progress="1">
<p:inputport="in-memory.in">
<p:pipestep="convert"port="result.in-memory"/>
</p:input>
<p:with-optionname="href"select="concat($output-dir-uri,$output-name,'.ebrl')"/>
</px:epub3-store>
</p:when>
<p:otherwisepx:message="Storing">
<p:documentation>
mimetype and META-INF/container.xml may be omitted when the eBraille
publication is not packaged in an EPUB container.
</p:documentation>
<px:fileset-filtername="filter-mimetype"href="mimetype">
<p:inputport="source.in-memory">
<p:pipestep="convert"port="result.in-memory"/>
</p:input>
</px:fileset-filter>
<p:choosename="filter-container">
<p:whentest="$include-original-text">
<p:outputport="fileset"primary="true">
<p:pipestep="filter-mimetype"port="not-matched"/>
</p:output>
<p:outputport="in-memory"sequence="true">
<p:pipestep="filter-mimetype"port="not-matched.in-memory"/>
</p:output>
<p:sink/>
</p:when>
<p:otherwise>
<p:outputport="fileset"primary="true">
<p:pipestep="filter"port="not-matched"/>
</p:output>
<p:outputport="in-memory"sequence="true">
<p:pipestep="filter"port="not-matched.in-memory"/>
</p:output>
<p:sink/>
<px:fileset-filtername="filter"href="META-INF/container.xml">
<p:inputport="source">
<p:pipestep="filter-mimetype"port="not-matched"/>
</p:input>
<p:inputport="source.in-memory">
<p:pipestep="filter-mimetype"port="not-matched.in-memory"/>
</p:input>
</px:fileset-filter>
<p:sink/>
</p:otherwise>
</p:choose>
<px:fileset-store>
<p:inputport="in-memory.in">
<p:pipestep="filter-container"port="in-memory"/>
</p:input>
</px:fileset-store>
</p:otherwise>
</p:choose>
<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>