Skip to content

Commit

Permalink
Merge pull request #449 from ndw/debug-intermediat-forms
Browse files Browse the repository at this point in the history
Add parameters to capture intermediate transformation results
  • Loading branch information
ndw authored Jan 16, 2024
2 parents e8e7cfc + e60f7cf commit 5b2673f
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 9 deletions.
91 changes: 91 additions & 0 deletions src/guide/xml/ref-params.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@ each image.
</varlistentry>
<varlistentry>
<term>
<enumvalue>intermediate-results</enumvalue>
</term>
<listitem>
<para>Output the resolved names of intermediate result documents
(<parameter>transformed-docbook-input</parameter>
and <parameter>transformed-docbook-output</parameter>) if they are used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<enumvalue>intra-chunk-links</enumvalue>
</term>
<listitem>
Expand Down Expand Up @@ -5507,5 +5518,85 @@ in the online stylesheets (but might in the future).</para>
</refsection>
</refentry>

<refentry>
<refmeta>
<fieldsynopsis>
<type>xs:string?</type>
<varname>transformed-docbook-input</varname>
<initializer>()</initializer>
</fieldsynopsis>
</refmeta>
<refnamediv>
<refpurpose>URI for transformed DocBook input</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>Broadly speaking, the DocBook transformation process has
three phases:</para>
<orderedlist>
<listitem>
<para>The DocBook input supplied by the user is run through a
series of transformations to produce a document that is ready
to be transformed to HTML. (See <xref linkend="preprocessing-pipeline"/>.)</para>
</listitem>
<listitem>
<para>That document is transformed into “HTML”. It’s not really HTML (yet)
because some aspects (footnotes, chunking, etc.) are not yet resolved.
(See <parameter>transformed-docbook-output</parameter>.)
</para>
</listitem>
<listitem>
<para>The “HTML” from the previous step is transformed to produce one
(or more) HTML results.
</para>
</listitem>
</orderedlist>
<para>If the <parameter>transformed-docbook-input</parameter> parameter is not the empty
sequence, it is assumed to be a URI. It will be made absolute against the base URI of the
input document.
The transformed DocBook that results from step 1 above will be
output to that location.</para>
</refsection>
</refentry>

<refentry>
<refmeta>
<fieldsynopsis>
<type>xs:string?</type>
<varname>transformed-docbook-output</varname>
<initializer>()</initializer>
</fieldsynopsis>
</refmeta>
<refnamediv>
<refpurpose>URI for transformed DocBook output</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>Broadly speaking, the DocBook transformation process has
three phases:</para>
<orderedlist>
<listitem>
<para>The DocBook input supplied by the user is run through a
series of transformations to produce a document that is ready
to be transformed to HTML. (See <parameter>transformed-docbook-input</parameter>.)</para>
</listitem>
<listitem>
<para>That document is transformed into “HTML”. It’s not really HTML (yet)
because some aspects (footnotes, chunking, etc.) are not yet resolved.
</para>
</listitem>
<listitem>
<para>The “HTML” from the previous step is transformed to produce one
(or more) HTML results.
</para>
</listitem>
</orderedlist>
<para>If the <parameter>transformed-docbook-output</parameter>
parameter is not the empty sequence, it is assumed to be a URI. It
will be made absolute against the base URI of the input document.
The transformed “HTML” that results from step 2 above will be
output to that location.</para>
</refsection>
</refentry>

</reference>
49 changes: 40 additions & 9 deletions src/main/xslt/docbook.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:dbe="http://docbook.org/ns/docbook/errors"
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:fp="http://docbook.org/ns/docbook/functions/private"
Expand Down Expand Up @@ -203,22 +204,52 @@
map { xs:QName('vp:starting-base-uri'): $starting-base-uri })"/>
</xsl:variable>

<!--
<xsl:result-document href="/tmp/out.xml" method="xml" indent="yes">
<xsl:if test="string($transformed-docbook-input) != ''">
<xsl:try>
<xsl:variable name="href"
select="resolve-uri($transformed-docbook-input, base-uri(/))"/>
<xsl:result-document href="{$href}" method="xml" indent="no"
exclude-result-prefixes="#all">
<xsl:sequence select="$document"/>
</xsl:result-document>
<xsl:if test="$v:debug = 'intermediate-results'">
<xsl:message select="'Transformed DocBook input saved:', $href"/>
</xsl:if>
<xsl:catch>
<xsl:message select="'Failed to save transformed input:', $transformed-docbook-input"/>
<xsl:message select="$err:description"/>
</xsl:catch>
</xsl:try>
</xsl:if>

<xsl:variable name="transformed-html" as="document-node()">
<xsl:apply-templates select="$document" mode="m:docbook">
<xsl:with-param name="vp:loop-count" select="1" tunnel="yes"/>
</xsl:apply-templates>
</xsl:result-document>
-->
</xsl:variable>

<xsl:if test="string($transformed-docbook-output) != ''">
<xsl:try>
<xsl:variable name="href"
select="resolve-uri($transformed-docbook-output, base-uri(/))"/>
<xsl:result-document href="{$href}" method="xml" indent="no"
exclude-result-prefixes="#all">
<xsl:sequence select="$transformed-html"/>
</xsl:result-document>
<xsl:if test="$v:debug = 'intermediate-results'">
<xsl:message select="'Transformed DocBook output saved:', $href"/>
</xsl:if>
<xsl:catch>
<xsl:message select="'Failed to save transformed output:', $transformed-docbook-output"/>
<xsl:message select="$err:description"/>
</xsl:catch>
</xsl:try>
</xsl:if>

<xsl:variable name="result" as="document-node()">
<xsl:call-template name="t:chunk-cleanup">
<xsl:with-param name="docbook" select="$document"/>
<xsl:with-param name="source">
<xsl:apply-templates select="$document" mode="m:docbook">
<xsl:with-param name="vp:loop-count" select="1" tunnel="yes"/>
</xsl:apply-templates>
</xsl:with-param>
<xsl:with-param name="source" select="$transformed-html"/>
</xsl:call-template>
</xsl:variable>

Expand Down

0 comments on commit 5b2673f

Please sign in to comment.