Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: First draft for splitting at xml:base #46

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DocBook-Cookbook.xpr
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,8 @@
<String>http://www.w3.org/1998/Math/MathML</String>
<String>svg</String>
<String>http://www.w3.org/2000/svg</String>
<String>fo</String>
<String>http://www.w3.org/1999/XSL/Format</String>
</String-array>
</entry>
</serializableOrderedMap>
Expand Down Expand Up @@ -1679,4 +1681,4 @@
<file name="en/xml/legalnotice.xml"/>
</folder>
</projectTree>
</project>
</project>
1 change: 1 addition & 0 deletions en/xml/dbc-structure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<xi:include href="structure/topic.revision-list.xml"/>
<xi:include href="structure/topic.acronym-list.xml"/>
<xi:include href="structure/topic.splitting-into-topics.xml"/>
<xi:include href="structure/topic.splitdb-xmlbase.xml"/>
<xi:include href="structure/topic.assemble-topics.xml"/>
<xi:include href="structure/topic.create-assembly-file.xml"/>
<xi:include href="structure/topic.use-entities.xml"/>
Expand Down
243 changes: 243 additions & 0 deletions en/xml/structure/splitdb/db-xmlbase-split.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

-->
<xsl:stylesheet version="1.0"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/chunker.xsl"/>

<xsl:param name="base.dir" select="'out/'"/>
<xsl:param name="rootid"/>
<xsl:param name="chunk.quietly" select="0"/>

<xsl:param name="dbsplit.root.basename">index</xsl:param>
<xsl:param name="dbsplit.ext">.xml</xsl:param>

<!-- ================================================================== -->
<xsl:template name="dirname">
<xsl:param name="filename" select="''"/>
<xsl:if test="contains($filename, '/')">
<xsl:value-of select="substring-before($filename, '/')"/>
<xsl:text>/</xsl:text><!-- separator -->
<xsl:call-template name="dirname">
<xsl:with-param name="filename" select="substring-after($filename, '/')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="basename">
<!-- We assume all filenames are really URIs and use "/" -->
<xsl:param name="filename"></xsl:param>
<xsl:param name="recurse" select="false()"/>

<xsl:choose>
<xsl:when test="substring-after($filename, '/') != ''">
<xsl:call-template name="basename">
<xsl:with-param name="filename" select="substring-after($filename, '/')"/>
<xsl:with-param name="recurse" select="true()"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$filename"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- ================================================================== -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<!-- ================================================================== -->
<xsl:template match="*" mode="xmlbase">
<xsl:param name="path"/>

<xsl:variable name="xbase" select="@xml:base"/>
<xsl:variable name="dir">
<xsl:variable name="tmp">
<xsl:if test="$xbase">
<xsl:call-template name="dirname">
<xsl:with-param name="filename" select="$xbase"/>
</xsl:call-template>
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="$tmp">
<xsl:value-of select="concat($tmp, $path)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<!-- <xsl:message>xmlbase mode:
element <xsl:value-of select="concat(local-name(.), ' ', @xml:id)"/>
path=<xsl:value-of select="$path"/></xsl:message>-->

<xsl:choose>
<xsl:when test="not(ancestor::*[1])">
<xsl:value-of select="$path"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="ancestor::*[1]" mode="xmlbase">
<xsl:with-param name="path" select="$dir"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- ================================================================== -->

<xsl:template name="get.filename">
<xsl:param name="node" select="."/>

<xsl:variable name="basename">
<xsl:call-template name="basename">
<xsl:with-param name="filename" select="$node/@xml:base"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="dirs">
<!--<xsl:call-template name="get.xml.base">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>-->
<xsl:message>START</xsl:message>
<xsl:apply-templates select="$node" mode="xmlbase"/>
<xsl:message>END</xsl:message>
</xsl:variable>

<xsl:value-of select="concat($dirs, $basename)"/>
</xsl:template>

<xsl:template name="get.xml.base_toms">
<xsl:param name="node" select="."/>
<xsl:param name="path" select="''"/>

<xsl:variable name="xmlbase" select="$node/@xml:base"/>
<xsl:variable name="basename">
<xsl:call-template name="basename">
<xsl:with-param name="filename" select="$xmlbase"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="dirs">
<xsl:message>start</xsl:message>
<xsl:for-each select="$node/ancestor-or-self::*/@xml:base">
<xsl:message>base=<xsl:value-of select="concat(name(..),'@', .)"/></xsl:message>
<xsl:call-template name="dirname">
<xsl:with-param name="filename" select="."/>
</xsl:call-template>
</xsl:for-each>
<xsl:message>End</xsl:message>
</xsl:variable>

<xsl:value-of select="translate($dirs, '/', '-')"/>

<!-- <xsl:variable name="tmppath">
<xsl:choose>
<xsl:when test="$path = '' and $dir != ''">
<xsl:value-of select="translate($dir, '/', '-')"/>
</xsl:when>
<xsl:when test="$path != '' and $dir != ''">
<xsl:value-of select="concat($path, '-', $dir)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:if test="$xmlbase">
<xsl:message>get.xml.base (<xsl:value-of select="$xmlbase"/>)
dir = "<xsl:value-of select="$dir"/>"
path = "<xsl:value-of select="$path"/>"</xsl:message>
<xsl:value-of select="$tmppath"/>
</xsl:if>
<xsl:if test="$node/..">
<xsl:call-template name="get.xml.base">
<xsl:with-param name="node" select="$node/.."/>
<xsl:with-param name="path" select="$tmppath"/>
</xsl:call-template>
</xsl:if>-->
</xsl:template>


<xsl:template name="get.xml.base">
<xsl:param name="node" select="."/>
<xsl:param name="separator">.</xsl:param>
<xsl:param name="path" select="''"/>
<xsl:variable name="xmlbase" select="$node/@xml:base"/>
<xsl:variable name="dir">
<!--<xsl:call-template name="get_dirname">
<xsl:with-param name="path_to_split" select="$xmlbase"/>
</xsl:call-template>-->
<xsl:call-template name="dirname">
<xsl:with-param name="filename" select="$xmlbase"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="temp_path" select="concat($dir, $separator, $path)"/>

<xsl:if test="$xmlbase != ''">
<xsl:value-of select="$temp_path"/>
<xsl:message> DIRNAME: <xsl:value-of select="$temp_path"/>
</xsl:message>
</xsl:if>
<xsl:if test="$node/..">
<xsl:call-template name="get.xml.base">
<xsl:with-param name="node" select="$node/.."/>
<xsl:with-param name="path" select="$temp_path"/>
</xsl:call-template>
</xsl:if>
</xsl:template>


<!-- ================================================================== -->
<xsl:template match="/*|*[@xml:base != '']">
<xsl:variable name="dir">
<!-- <xsl:call-template name="get.filename"/>-->
<xsl:apply-templates select="." mode="xmlbase"/>
</xsl:variable>
<xsl:variable name="basename">
<xsl:call-template name="basename">
<xsl:with-param name="filename" select="@xml:base"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="filename" select="concat($dir, $basename, $dbsplit.ext)"/>

<xsl:call-template name="write.chunk">
<xsl:with-param name="method">xml</xsl:with-param>
<xsl:with-param name="filename">
<xsl:choose>
<xsl:when test="not(parent::*) and not(/*/@xml:base)">
<xsl:value-of select="concat($base.dir, $dbsplit.root.basename, $dbsplit.ext)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($base.dir, $filename)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="indent" select="'yes'"/>
<xsl:with-param name="encoding">UTF-8</xsl:with-param>
<xsl:with-param name="content">
<xsl:copy-of select="preceding-sibling::processing-instruction() |
preceding-sibling::comment()"/>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:with-param>
</xsl:call-template>
<!--<xi:include href="{$filename}"/>-->
<xsl:element name="include" namespace="http://www.w3.org/2001/XInclude">
<xsl:attribute name="href">
<xsl:value-of select="$filename"/>
</xsl:attribute>
</xsl:element>
</xsl:template>

</xsl:stylesheet>
74 changes: 74 additions & 0 deletions en/xml/structure/topic.splitdb-xmlbase.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
License CC BY-NC-SA 3.0

This work is licensed under the
"Namensnennung – Keine kommerzielle Nutzung – Weitergabe unter
gleichen Bedingungen 3.0 Deutschland (CC BY-NC-SA 3.0)"
http://creativecommons.org/licenses/by-nc-sa/3.0/de/deed.de

Read the English translation here:

"Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)"
http://creativecommons.org/licenses/by-nc-sa/3.0/

-->
<?xml-model href="file:../5.1/dbref.rnc" type="application/relax-ng-compact-syntax"?>
<section xml:id="dbc.structure.splitdb-xmlbase" userlevel="easy"
remap="topic" version="5.1"
xmlns="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Splitting DocBook 5 Documents at <tag class="attribute">xml:base</tag> Attributes</title>
<info>
<keywordset>
<keyword>splitting</keyword>
<keyword>xml:base</keyword>
</keywordset>
<subjectset>
<subject>
<subjectterm>modules</subjectterm>
</subject>
</subjectset>
</info>

<section role="problem">
<title>Problem</title>
<para>You have a big DocBook document, like a book, which contains
<tag class="attribute">xml:base</tag> attributes. You want to get files
that are splitted at that attribute and replaced by an XInclude element.
</para>
</section>
<section role="solution">
<title>Solution</title>
<para>Use the <filename linkend="li.db-xmlbase-split.xsl"
>db-xmlbase-split.xsl</filename> stylesheet. For example, lets assume
the following DocBook 5 document:</para>
<screen language="xml"><xi:include href="splitdb/article-xmlbase.xml" parse="text"/></screen>
<para>Applying the above template would lead to the following tree:</para>
<screen>out/
├── a/
│   └── index.xml
├── b/
│   └── index.xml
└── index.xml</screen>
</section>
<section role="discussion">
<title>Discussion</title>
<para>TBD.</para>
</section>
<section role="seealso">
<title>See Also</title>
<itemizedlist>
<listitem>
<para><xref linkend="dbc.structure.splitdb"/></para>
</listitem>
<listitem xml:id="li.db-xmlbase-split.xsl">
<para><link xlink:href="https://github.com/tomschr/dbcookbook/raw/develop/en/xml/structure/splitdb/db-xmlbase-split.xsl"/></para>
</listitem>
<listitem>
<para><link xlink:href="https://www.w3.org/TR/xmlbase/"/></para>
</listitem>
</itemizedlist>
</section>
</section>