From 88b90107acd0c43eb5ec43c396346f7f5f75afef Mon Sep 17 00:00:00 2001 From: Frank Steimke Date: Sun, 10 Mar 2024 12:31:21 +0100 Subject: [PATCH 1/3] Supports copy instructions for media files --- src/guide/xml/ch03.xml | 42 +++++++- src/guide/xml/ref-params.xml | 29 ++++- src/guide/xml/ref-templates.xml | 33 +++++- src/main/xslt/docbook-paged.xsl | 10 +- src/main/xslt/docbook.xsl | 19 +++- src/main/xslt/main.xsl | 1 + src/main/xslt/modules/chunk-output.xsl | 2 +- src/main/xslt/modules/copyinstructions.xsl | 105 +++++++++++++++++++ src/main/xslt/modules/objects.xsl | 5 +- src/main/xslt/modules/variable.xsl | 24 +++++ src/test/resources/xml/test/instructions.xml | 1 + 11 files changed, 257 insertions(+), 14 deletions(-) create mode 100644 src/main/xslt/modules/copyinstructions.xsl create mode 100644 src/test/resources/xml/test/instructions.xml diff --git a/src/guide/xml/ch03.xml b/src/guide/xml/ch03.xml index bd72b10652..aca7c25662 100644 --- a/src/guide/xml/ch03.xml +++ b/src/guide/xml/ch03.xml @@ -346,11 +346,11 @@ subdirectory. the desired results for each combination of input and output arrangements. -Remember that in each case, the questions are: can the -stylesheets find the media files to query them and are the correct -HTML references produced? Actually copying the media files from where -they are in the source system to where they need to be in the HTML is -“not our problem.” +Remember that in each case, the questions are: can the stylesheets find the media files to + query them and are the correct HTML references produced? Actually copying the media files + from where they are in the source system to where they need to be in the HTML is “not our + problem”, but the stylesheets may offer some help. See for details. @@ -504,6 +504,38 @@ for example, run: to see the results of processing “mo-3” in scenario 2. The output will be in the build/actual directory. The build target all_mo_tests will run them all. + +
+ Copy instructions for media files + Because handling of media files can be complicated, the stylesheets may provide support + under certain circumstances. If the destination of the transformation is known within the + stylesheets, we can infer the destination for media files as well, and a script with + instructions for copying the media files can be created on request. If the expath file:copy function is + available, the copy instructions can even be executed. This is the case, for example, if you + are using Saxon-PE or Saxon-EE. + Two prerequisites must be met for copy instructions to be created and, if possible, + executed: + + + The target of the transformation must be specified with the two parameters + chunk-output-base-uri and chunk. In + other words: the support for copying media files only works for chunked output in + accordance with . If you are not interested + in "chunked HTML", but prefer a single HTML file as output, you can set the parameter + chunk-include to the empty sequence (). You may + call this "fake chunking" if you want, but we have to rely on this trick because there + is currently no other way to determine the destination of the transformation + + + You must request copy instructions by setting the parameter + copyinstructions-uri to a file path. The copy instructions will be + written to this file. + + + The template is responsible for + writing the file which contains copy instructions. +
diff --git a/src/guide/xml/ref-params.xml b/src/guide/xml/ref-params.xml index ecf67aa068..dd47e0f58e 100644 --- a/src/guide/xml/ref-params.xml +++ b/src/guide/xml/ref-params.xml @@ -2472,6 +2472,29 @@ settings. See also table-accessibility. + + + + + xs:string? + copyinstructions-uri + + + + URI for a file with copy instructions for media files + + + Description + You may specify the path of a file with instructions for copying media files in this + parameter. Please keep in mind, that support for copy-instructions for media files will only + work for "chunked" output, see for + details. If it is a relative path, it will be resolved against + mediaobject-output-base-uri. The template + is responsible for writing the file, it + determines the format of the "instructions". + + + @@ -2580,8 +2603,10 @@ audio files, etc.) is complicated. See . The mediaobject-output-base-uri is used to compute the base URI of media objects in the output. -It defaults to the empty string. -See v:mediaobject-output-base-uri. +It defaults to the empty string. In this case, +the img elements in the generated HTML file(s) +will reference the mediaobject files in their original places. +See v:mediaobject-input-base-uri. diff --git a/src/guide/xml/ref-templates.xml b/src/guide/xml/ref-templates.xml index da040b117d..7d782fefc9 100644 --- a/src/guide/xml/ref-templates.xml +++ b/src/guide/xml/ref-templates.xml @@ -277,7 +277,38 @@ the element’s content. - + + + + t:write-copyinstructions + {http://docbook.org/ns/docbook/templates}write-copyinstructions + + + t:write-copyinstructions + Writes a file which contains copy instructions for mediaobject files + template + + + Description + This template writes a file at copyinstructions-uri for copying + the media files in the template parameter $instructions, which is a non-empty + sequence of maps with source and destination. + The default implementation will create an XML file with copyinstructions as + root element, and one copy Element for each map in $instructions. + <copyinstructions> + <copy source= "file:/mnt/shared/kosit/xslTNG/src/test/resources/media/duck-small.gif" + destination="file:/home/frank/kosit/xslTNG/test/html/duck-small.gif"/> +</copyinstructions> + + You may use a customization layer with your own implementation of this template to create a UNIX or Windows Script file. + Please note, that this templete will only be called if the expath function + {http://expath.org/ns/file}:copy is not available. Otherwise, the copy + instruction will pe performed by the stylesheets, in which case the file at + copyinstructions-uri will become a logfile with a slightly + different format. + + + diff --git a/src/main/xslt/docbook-paged.xsl b/src/main/xslt/docbook-paged.xsl index 7342d0c73f..c49130e89f 100644 --- a/src/main/xslt/docbook-paged.xsl +++ b/src/main/xslt/docbook-paged.xsl @@ -117,10 +117,16 @@ - + + + +
+ mode="m:chunk-cleanup"> + + +
diff --git a/src/main/xslt/docbook.xsl b/src/main/xslt/docbook.xsl index 82f9d7341e..fe5c36908e 100644 --- a/src/main/xslt/docbook.xsl +++ b/src/main/xslt/docbook.xsl @@ -5,7 +5,9 @@ xmlns:err='http://www.w3.org/2005/xqt-errors' xmlns:ext="http://docbook.org/extensions/xslt" xmlns:f="http://docbook.org/ns/docbook/functions" + xmlns:file="http://expath.org/ns/file" xmlns:fp="http://docbook.org/ns/docbook/functions/private" + xmlns:ghost="http://docbook.org/ns/docbook/ephemeral" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:m="http://docbook.org/ns/docbook/modes" xmlns:mp="http://docbook.org/ns/docbook/modes/private" @@ -275,7 +277,15 @@ - + + + + + + + + + + + - + \ No newline at end of file diff --git a/src/main/xslt/main.xsl b/src/main/xslt/main.xsl index 15c5d7001b..7141ea8d25 100644 --- a/src/main/xslt/main.xsl +++ b/src/main/xslt/main.xsl @@ -62,6 +62,7 @@ + diff --git a/src/main/xslt/modules/chunk-output.xsl b/src/main/xslt/modules/chunk-output.xsl index 73680dc39a..66d668c23c 100644 --- a/src/main/xslt/modules/chunk-output.xsl +++ b/src/main/xslt/modules/chunk-output.xsl @@ -215,7 +215,7 @@ - + diff --git a/src/main/xslt/modules/copyinstructions.xsl b/src/main/xslt/modules/copyinstructions.xsl new file mode 100644 index 0000000000..5b5547a3ec --- /dev/null +++ b/src/main/xslt/modules/copyinstructions.xsl @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/xslt/modules/objects.xsl b/src/main/xslt/modules/objects.xsl index 70c8b10094..eb8a769356 100644 --- a/src/main/xslt/modules/objects.xsl +++ b/src/main/xslt/modules/objects.xsl @@ -5,6 +5,7 @@ xmlns:ext="http://docbook.org/extensions/xslt" xmlns:f="http://docbook.org/ns/docbook/functions" xmlns:fp="http://docbook.org/ns/docbook/functions/private" + xmlns:ghost="http://docbook.org/ns/docbook/ephemeral" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:m="http://docbook.org/ns/docbook/modes" xmlns:map="http://www.w3.org/2005/xpath-functions/map" @@ -757,6 +758,7 @@ + @@ -767,12 +769,13 @@ + - + diff --git a/src/main/xslt/modules/variable.xsl b/src/main/xslt/modules/variable.xsl index 654597f523..cc303641e2 100644 --- a/src/main/xslt/modules/variable.xsl +++ b/src/main/xslt/modules/variable.xsl @@ -104,6 +104,30 @@ then $mediaobject-output-base-uri else $mediaobject-output-base-uri || '/'"/> + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/xml/test/instructions.xml b/src/test/resources/xml/test/instructions.xml new file mode 100644 index 0000000000..05b363375e --- /dev/null +++ b/src/test/resources/xml/test/instructions.xml @@ -0,0 +1 @@ + \ No newline at end of file From 6b79f26ae467ea353dbb4ad42be2a30432d9785e Mon Sep 17 00:00:00 2001 From: Frank Steimke Date: Tue, 14 May 2024 07:25:09 +0200 Subject: [PATCH 2/3] Removed own debug message --- src/main/xslt/modules/copyinstructions.xsl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/xslt/modules/copyinstructions.xsl b/src/main/xslt/modules/copyinstructions.xsl index 5b5547a3ec..076f805548 100644 --- a/src/main/xslt/modules/copyinstructions.xsl +++ b/src/main/xslt/modules/copyinstructions.xsl @@ -11,7 +11,6 @@ - From 79505c2de1eab55dae403c37d7ad511e51a5b25e Mon Sep 17 00:00:00 2001 From: Frank Steimke Date: Thu, 16 May 2024 22:39:32 +0200 Subject: [PATCH 3/3] resolve img/@src against chunk-output-base-uri --- src/main/xslt/modules/copyinstructions.xsl | 10 +++++----- src/main/xslt/modules/variable.xsl | 13 ------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/main/xslt/modules/copyinstructions.xsl b/src/main/xslt/modules/copyinstructions.xsl index 076f805548..bc5d560f85 100644 --- a/src/main/xslt/modules/copyinstructions.xsl +++ b/src/main/xslt/modules/copyinstructions.xsl @@ -12,7 +12,7 @@ - + @@ -28,9 +28,9 @@ - + @@ -87,8 +87,8 @@ - - + + - - - - - - - - - - -