[yelp-xsl] dita: Process from map files, get some linking right
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp-xsl] dita: Process from map files, get some linking right
- Date: Thu, 8 Nov 2012 16:22:27 +0000 (UTC)
commit 8069fc1497eaa2d22d7a384f133224cf183cbe8a
Author: Shaun McCance <shaunm gnome org>
Date: Thu Nov 8 11:22:01 2012 -0500
dita: Process from map files, get some linking right
xslt/dita/common/dita-map.xsl | 95 ++++++++++++++
xslt/dita/common/dita-selectors.mod | 14 ++-
xslt/dita/html/dita2html-block.xsl | 10 +-
xslt/dita/html/dita2html-inline.xsl | 2 +-
xslt/dita/html/dita2html-topic.xsl | 238 ++++++++++++++++++++++++++++++----
xslt/dita/html/dita2xhtml.xsl | 1 +
6 files changed, 325 insertions(+), 35 deletions(-)
---
diff --git a/xslt/dita/common/dita-map.xsl b/xslt/dita/common/dita-map.xsl
new file mode 100644
index 0000000..52e5e00
--- /dev/null
+++ b/xslt/dita/common/dita-map.xsl
@@ -0,0 +1,95 @@
+<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
+<!--
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free
+Software Foundation; either version 2 of the License, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program; see the file COPYING.LGPL. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+-->
+<!DOCTYPE xsl:stylesheet [
+<!ENTITY % selectors SYSTEM "dita-selectors.mod">
+%selectors;
+]>
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:str="http://exslt.org/strings"
+ exclude-result-prefixes="exsl str"
+ version="1.0">
+
+<!--!!==========================================================================
+DITA Maps
+
+REMARK: Describe this module
+-->
+
+
+<xsl:param name="dita.map.base" select="/"/>
+
+<xsl:variable name="_dita.map">
+ <xsl:apply-templates mode="dita.map.copy.mode" select="/&map_map;"/>
+</xsl:variable>
+<xsl:param name="dita.map" select="exsl:node-set($_dita.map)"/>
+
+<xsl:template mode="dita.map.copy.mode" match="*">
+ <xsl:param name="base"/>
+ <xsl:copy>
+ <xsl:copy-of select="@*"/>
+ <xsl:apply-templates mode="dita.map.copy.mode">
+ <xsl:with-param name="base" select="$base"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template mode="dita.map.copy.mode" match="&map_topicref;">
+ <xsl:param name="base"/>
+ <xsl:variable name="uri">
+ <xsl:choose>
+ <xsl:when test="contains(@href, ':') or starts-with(@href, '/')">
+ <xsl:value-of select="@href"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$base"/>
+ <xsl:value-of select="@href"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="@format = 'ditamap'">
+ <xsl:apply-templates mode="dita.map.copy.mode" select="document($uri, $dita.map.base)/*/*">
+ <xsl:with-param name="base">
+ <xsl:if test="contains($uri, '/')">
+ <xsl:for-each select="str:split($uri, '/')">
+ <xsl:if test="position() != last()">
+ <xsl:value-of select="."/>
+ <xsl:text>/</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy>
+ <xsl:copy-of select="@*[name(.) != 'href']"/>
+ <xsl:attribute name="href">
+ <xsl:value-of select="$uri"/>
+ </xsl:attribute>
+ <xsl:apply-templates mode="dita.map.copy.mode">
+ <xsl:with-param name="base" select="$base"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xslt/dita/common/dita-selectors.mod b/xslt/dita/common/dita-selectors.mod
index 36121dc..a299a4a 100644
--- a/xslt/dita/common/dita-selectors.mod
+++ b/xslt/dita/common/dita-selectors.mod
@@ -224,6 +224,8 @@ topic/ph
name(.) = 'filepath' or starts-with(@class, '- topic/ph sw-d/filepath ')]">
<!ENTITY topic_i "*[
name(.) = 'i' or starts-with(@class, '- topic/ph hi-d/i ')]">
+<!ENTITY topic_mainbooktitle "*[
+ name(.) = 'mainbooktitle' or starts-with(@class, '- topic/ph bookmap/mainbooktitle ')]">
<!ENTITY topic_menucascade "*[
name(.) = 'menucascade' or starts-with(@class, '- topic/ph hi-d/menucascade ')]">
<!ENTITY topic_systemoutput "*[
@@ -346,7 +348,17 @@ topic/text
<!-- ===========================================================================
topic/title
-->
-<!ENTITY topic_title "*[name(.) = 'title' or starts-with(@class, '- topic/title ')]">
+<!ENTITY topic_booktitle "*[
+ name(.) = 'booktitle' or starts-with(@class, '- topic/title bookmap/booktitle ')]">
+<!ENTITY topic_title "*[
+ name(.) = 'title' or (
+ starts-with(@class, '- topic/title ')
+ and not(starts-with(@class, '- topic/title bookmap/booktitle '))
+ )]">
+<!ENTITY topic_title_all "*[
+ name(.) = 'title' or name(.) = 'booktitle' or
+ starts-with(@class, '- topic/title ')
+]">
<!-- ===========================================================================
topic/topic
diff --git a/xslt/dita/html/dita2html-block.xsl b/xslt/dita/html/dita2html-block.xsl
index cb911d4..e90cc26 100644
--- a/xslt/dita/html/dita2html-block.xsl
+++ b/xslt/dita/html/dita2html-block.xsl
@@ -166,14 +166,14 @@ FIXME
<xsl:call-template name="dita.id"/>
<xsl:call-template name="html.lang.attrs"/>
<div class="inner">
- <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_title;"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_title_all;"/>
<div class="region">
<xsl:if test="$style = 'listing'">
<xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_desc;"/>
</xsl:if>
<div class="contents">
<xsl:apply-templates mode="dita2html.topic.mode"
- select="$conref/node()[not(self::&topic_title; or self::&topic_desc;)]"/>
+ select="$conref/node()[not(self::&topic_title_all; or self::&topic_desc;)]"/>
</div>
<xsl:if test="$style = 'figure'">
<xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_desc;"/>
@@ -274,9 +274,9 @@ FIXME
in the child node list. And there could be more than one, but all
but the first are ignored. Apparently. Spec isn't very clear, but
this is the OT's behavior. -->
- <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_title;[1]"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_title_all;[1]"/>
<div class="region">
- <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/node()[not(self::&topic_title;)]"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/node()[not(self::&topic_title_all;)]"/>
</div>
</div>
</xsl:template>
@@ -308,7 +308,7 @@ FIXME
</xsl:template>
<!-- = title = -->
-<xsl:template mode="dita2html.topic.mode" match="&topic_title;">
+<xsl:template mode="dita2html.topic.mode" match="&topic_title_all;">
<xsl:variable name="conref" select="yelp:dita.ref.conref(.)"/>
<xsl:variable name="depth" select="count(ancestor::&topic_topic_all;) + 1"/>
<xsl:variable name="depth_">
diff --git a/xslt/dita/html/dita2html-inline.xsl b/xslt/dita/html/dita2html-inline.xsl
index 15f5273..16bd8c0 100644
--- a/xslt/dita/html/dita2html-inline.xsl
+++ b/xslt/dita/html/dita2html-inline.xsl
@@ -239,7 +239,7 @@ FIXME
</xsl:choose>
</xsl:variable>
<xsl:variable name="tnode" select="key('dita.id.key', $frag)"/>
- <xsl:apply-templates mode="dita2html.topic.mode" select="$tnode/&topic_title;/node()"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$tnode/&topic_title_all;/node()"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
diff --git a/xslt/dita/html/dita2html-topic.xsl b/xslt/dita/html/dita2html-topic.xsl
index 4681306..3e5ab44 100644
--- a/xslt/dita/html/dita2html-topic.xsl
+++ b/xslt/dita/html/dita2html-topic.xsl
@@ -21,9 +21,11 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:str="http://exslt.org/strings"
xmlns:yelp="http://projects.gnome.org/yelp/"
xmlns="http://www.w3.org/1999/xhtml"
- exclude-result-prefixes="yelp"
+ exclude-result-prefixes="exsl str yelp"
version="1.0">
<!--!!==========================================================================
@@ -33,40 +35,186 @@ REMARK: Describe this module
-->
-<!-- == Matched Templates == -->
+<xsl:template match="/">
+ <xsl:choose>
+ <xsl:when test="&map_map;">
+ <xsl:for-each select="$dita.map">
+ <xsl:call-template name="html.output">
+ <xsl:with-param name="node" select="&map_map;"/>
+ <xsl:with-param name="href" select="concat('index', $html.extension)"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>Unmatched root element: </xsl:text>
+ <xsl:value-of select="local-name(*)"/>
+ </xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+<!-- == map == -->
+
+<!-- = map % html.output.after.mode = -->
+<xsl:template mode="html.output.after.mode" match="/&map_map;">
+ <xsl:for-each select="//&map_topicref;">
+ <xsl:call-template name="html.output">
+ <xsl:with-param name="href">
+ <xsl:call-template name="dita.ref.href.target"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:for-each>
+</xsl:template>
+
+<!-- = map % html.body.mode = -->
+<xsl:template mode="html.body.mode" match="&map_map;">
+ <div class="hgroup">
+ <h1 class="title">
+ <span class="title">
+ <xsl:apply-templates mode="dita2html.topic.mode" select="&topic_title_all;/node()"/>
+ </span>
+ </h1>
+ </div>
+ <div class="region">
+ <xsl:call-template name="dita.id"/>
+ <xsl:call-template name="html.lang.attrs"/>
+ <div class="links sectionlinks" role="navigation">
+ <ul>
+ <xsl:for-each select="&map_topicref;">
+ <li class="links">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:call-template name="dita.ref.href.target"/>
+ </xsl:attribute>
+ <xsl:choose>
+ <xsl:when test="@navtitle">
+ <xsl:value-of select="@navtitle"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates mode="dita2html.topic.mode"
+ select="document(@href, $dita.map.base)/&topic_topic_all;/&topic_title_all;/node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </a>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </div>
+ </div>
+</xsl:template>
+
-<!--%# html.title.mode -->
-<xsl:template mode="html.title.mode" match="&topic_topic;">
- <xsl:value-of select="&topic_title;"/>
+<!-- == topicref == -->
+
+<!-- = topicref % html.title.mode = -->
+<xsl:template mode="html.title.mode" match="&map_topicref;">
+ <xsl:value-of select="document(@href, $dita.map.base)/&topic_topic_all;/&topic_title_all;"/>
</xsl:template>
-<!--%# html.header.mode -->
-<xsl:template mode="html.header.mode" match="&topic_topic;">
+<!-- = topicref % html.header.mode = -->
+<xsl:template mode="html.header.mode" match="&map_topicref;">
+ <xsl:variable name="node" select="."/>
+ <xsl:variable name="direction">
+ <xsl:call-template name="l10n.direction"/>
+ </xsl:variable>
+ <xsl:variable name="sep">
+ <xsl:choose>
+ <xsl:when test="$direction = 'rtl'">
+ <xsl:text> Â </xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text> Â </xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
<div class="trails">
+ <div class="trail">
+ <a class="trail">
+ <xsl:attribute name="href">
+ <xsl:for-each select="str:split($node/@href, '/')">
+ <xsl:if test="position() != last()">
+ <xsl:text>../</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:text>index</xsl:text>
+ <xsl:value-of select="$html.extension"/>
+ </xsl:attribute>
+ <xsl:choose>
+ <xsl:when test="/&map_map;/&topic_booktitle;">
+ <xsl:apply-templates mode="dita2html.topic.mode"
+ select="/&map_map;/&topic_title_all;/&topic_mainbooktitle;/node()"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates mode="dita2html.topic.mode"
+ select="/&map_map;/&topic_title_all;/node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </a>
+ <xsl:value-of select="$sep"/>
+ <xsl:for-each select="ancestor::&map_topicref;">
+ <a class="trail">
+ <xsl:attribute name="href">
+ <xsl:for-each select="str:split($node/@href, '/')">
+ <xsl:if test="position() != last()">
+ <xsl:text>../</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:call-template name="dita.ref.href.target"/>
+ </xsl:attribute>
+ <xsl:choose>
+ <xsl:when test="@navtitle">
+ <xsl:value-of select="@navtitle"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates mode="dita2html.topic.mode"
+ select="document(@href, $dita.map.base)/&topic_topic_all;/&topic_title_all;/node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </a>
+ <xsl:value-of select="$sep"/>
+ </xsl:for-each>
+ </div>
</div>
- <!-- FIXME -->
- <!--
- <xsl:call-template name="mal2html.page.linktrails"/>
- -->
</xsl:template>
-<!--%# html.footer.mode -->
-<xsl:template mode="html.footer.mode" match="&topic_topic;">
+<!-- = topicref % html.footer.mode = -->
+<xsl:template mode="html.footer.mode" match="&map_topicref;">
<!-- FIXME -->
<!--
<xsl:call-template name="mal2html.page.about"/>
-->
</xsl:template>
-<!--%# html.body.mode -->
-<xsl:template mode="html.body.mode" match="&topic_topic;">
- <!-- FIXME: prevnext -->
- <xsl:apply-templates mode="dita2html.topic.mode" select="."/>
- <div class="clear"/>
+<!-- = topicref % html.body.mode = -->
+<xsl:template mode="html.body.mode" match="&map_topicref;">
+ <xsl:variable name="node" select="."/>
+ <xsl:variable name="subtopics">
+ <xsl:for-each select="&map_topicref;">
+ <xsl:copy>
+ <xsl:copy-of select="@*[name(.) != 'href']"/>
+ <xsl:attribute name="href">
+ <xsl:for-each select="str:split($node/@href, '/')">
+ <xsl:if test="position() != last()">
+ <xsl:text>../</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:value-of select="@href"/>
+ </xsl:attribute>
+ </xsl:copy>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="document(@href, $dita.map.base)/*">
+ <xsl:with-param name="subtopics" select="exsl:node-set($subtopics)/*"/>
+ </xsl:apply-templates>
</xsl:template>
-<!--%# html.css.mode -->
-<xsl:template mode="html.css.mode" match="&topic_topic;">
+
+<!-- == CSS == -->
+
+<xsl:template mode="html.css.mode" match="*">
+<!-- FIXME: open document for @lang -->
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
</xsl:param>
@@ -103,10 +251,13 @@ th, td { border: solid 1px; }
</xsl:template>
+<!-- == Matched Templates == -->
+
<!-- = topic = -->
-<xsl:template mode="dita2html.topic.mode" match="&topic_topic;">
+<xsl:template mode="dita2html.topic.mode" match="&topic_topic_all;">
+ <xsl:param name="subtopics"/>
<xsl:choose>
- <xsl:when test="parent::&topic_topic;">
+ <xsl:when test="parent::&topic_topic_all;">
<div class="sect">
<xsl:call-template name="dita.id"/>
<xsl:call-template name="html.lang.attrs"/>
@@ -116,13 +267,16 @@ th, td { border: solid 1px; }
</div>
</xsl:when>
<xsl:otherwise>
- <xsl:call-template name="_dita2html.topic.inner"/>
+ <xsl:call-template name="_dita2html.topic.inner">
+ <xsl:with-param name="subtopics" select="$subtopics"/>
+ </xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--#* _dita2html.topic.inner -->
<xsl:template name="_dita2html.topic.inner">
+ <xsl:param name="subtopics"/>
<xsl:variable name="conref" select="yelp:dita.ref.conref(.)"/>
<xsl:variable name="depth" select="count(ancestor::*) + 1"/>
<xsl:variable name="depth_">
@@ -141,16 +295,20 @@ th, td { border: solid 1px; }
<xsl:text>title</xsl:text>
</xsl:attribute>
<span class="title">
- <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_title;"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_title_all;/node()"/>
</span>
</xsl:element>
</div>
- <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_body;"/>
- <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_topic;"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_body;">
+ <xsl:with-param name="subtopics" select="$subtopics"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_topic_all;"/>
<xsl:apply-templates mode="dita2html.topic.mode" select="$conref/&topic_related-links;"/>
</xsl:template>
<xsl:template mode="dita2html.topic.mode" match="&topic_body;">
+ <xsl:param name="subtopics"/>
+ <xsl:variable name="node" select="."/>
<xsl:variable name="conref" select="yelp:dita.ref.conref(.)"/>
<div class="region">
<xsl:call-template name="dita.id"/>
@@ -158,6 +316,30 @@ th, td { border: solid 1px; }
<div class="contents">
<xsl:apply-templates mode="dita2html.topic.mode" select="$conref/node()"/>
</div>
+ <xsl:if test="$subtopics">
+ <div class="links sectionlinks" role="navigation">
+ <ul>
+ <xsl:for-each select="$subtopics">
+ <li class="links">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:call-template name="dita.ref.href.target"/>
+ </xsl:attribute>
+ <xsl:choose>
+ <xsl:when test="@navtitle">
+ <xsl:value-of select="@navtitle"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates mode="dita2html.topic.mode"
+ select="document(@href, $node)/&topic_topic_all;/&topic_title_all;/node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </a>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </div>
+ </xsl:if>
</div>
</xsl:template>
@@ -227,13 +409,13 @@ th, td { border: solid 1px; }
<xsl:template mode="dita2html.topic.mode" match="&topic_linklist;">
<xsl:choose>
- <xsl:when test="&topic_title; or &topic_desc; or &topic_linkinfo;">
+ <xsl:when test="&topic_title_all; or &topic_desc; or &topic_linkinfo;">
<li class="links">
<div class="links">
<xsl:call-template name="dita.id"/>
<xsl:call-template name="html.lang.attrs"/>
<div class="inner">
- <xsl:apply-templates mode="dita2html.topic.mode" select="&topic_title;"/>
+ <xsl:apply-templates mode="dita2html.topic.mode" select="&topic_title_all;"/>
<div class="region">
<xsl:apply-templates mode="dita2html.topic.mode" select="&topic_desc;"/>
<ul>
diff --git a/xslt/dita/html/dita2xhtml.xsl b/xslt/dita/html/dita2xhtml.xsl
index 956a68c..be7ae99 100644
--- a/xslt/dita/html/dita2xhtml.xsl
+++ b/xslt/dita/html/dita2xhtml.xsl
@@ -34,6 +34,7 @@ REMARK: Describe this module
<xsl:import href="../../common/ttml.xsl"/>
<xsl:import href="../../common/utils.xsl"/>
+<xsl:import href="../common/dita-map.xsl"/>
<xsl:import href="../common/dita-ref.xsl"/>
<xsl:param name="dita.ref.extension" select="$html.extension"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]