[yelp-xsl] Preliminary support for the experimental gloss extension
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp-xsl] Preliminary support for the experimental gloss extension
- Date: Fri, 8 Jul 2011 01:59:40 +0000 (UTC)
commit 0667cd9e0951dbc28a454a504a4132a74415fce6
Author: Shaun McCance <shaunm gnome org>
Date: Thu Jul 7 22:04:43 2011 -0400
Preliminary support for the experimental gloss extension
xslt/mallard/common/Makefile.am | 2 +-
xslt/mallard/common/mal-gloss.xsl | 115 ++++++++++++++++++++++++++++++++++
xslt/mallard/html/Makefile.am | 1 +
xslt/mallard/html/mal2html-gloss.xsl | 112 +++++++++++++++++++++++++++++++++
xslt/mallard/html/mal2html-page.xsl | 22 +++++++
xslt/mallard/html/mal2xhtml.xsl | 2 +
6 files changed, 253 insertions(+), 1 deletions(-)
---
diff --git a/xslt/mallard/common/Makefile.am b/xslt/mallard/common/Makefile.am
index f1682f1..9854ae6 100644
--- a/xslt/mallard/common/Makefile.am
+++ b/xslt/mallard/common/Makefile.am
@@ -1,5 +1,5 @@
xsldir=$(datadir)/yelp-xsl/xslt/mallard/common
-xsl_DATA = mal-if.xsl mal-link.xsl mal-sort.xsl
+xsl_DATA = mal-gloss.xsl mal-if.xsl mal-link.xsl mal-sort.xsl
EXTRA_DIST=$(xsl_DATA)
diff --git a/xslt/mallard/common/mal-gloss.xsl b/xslt/mallard/common/mal-gloss.xsl
new file mode 100644
index 0000000..9234821
--- /dev/null
+++ b/xslt/mallard/common/mal-gloss.xsl
@@ -0,0 +1,115 @@
+<?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.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+ xmlns:mal="http://projectmallard.org/1.0/";
+ xmlns:cache="http://projectmallard.org/cache/1.0/";
+ xmlns:gloss="http://projectmallard.org/experimental/gloss/";
+ xmlns:str="http://exslt.org/strings";
+ exclude-result-prefixes="mal cache gloss str"
+ version="1.0">
+
+<!--!!==========================================================================
+Mallard - Glossaries
+Common templates for the Mallard Glossary extension.
+
+This stylesheet contains utility templates for locating and linking to terms
+with the Mallard Glossary extension.
+-->
+
+
+<xsl:key name="mal.gloss.key"
+ match="/cache:cache//mal:info/gloss:term"
+ use="mal:title[1]"/>
+
+
+<!--**==========================================================================
+mal.gloss.terms
+Determine whether a glossary term matches a criterion.
+$match: A #{gloss:match} element containing criteria.
+$term: A #{gloss:term} element to attempt to match.
+
+This template determines whether a glossary term matches a condition, as given
+by a #{gloss:match} element. If the term matches, an empty string is output.
+Otherwise, a non-empty string is output.
+
+To determine if a term matches a set of matches, call this template for each
+#{gloss:match} element, then check if the concatenated result is empty.
+-->
+<xsl:template name="mal.gloss.match">
+ <xsl:param name="match"/>
+ <xsl:param name="term"/>
+ <xsl:if test="$match/@tags and not(str:split($match/@tags) = str:split($term/@tags))">
+ <xsl:text>x</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+
+<!--**==========================================================================
+mal.gloss.terms
+Output the glossary terms for a page or section.
+$node: The glossary #{page} or #{section} to output terms for.
+
+This template outputs the terms that should be displayed for ${node}. Terms are
+output as full copies from @{mal.cache}, except they the #{gloss:id} attribute
+added. This attribute contains an ID for the #{term} element in the cache, as
+generated by the #{generate-id} function.
+
+This template filters the results based on any #{gloss:match} elements in the
+#{info} child of ${node}, and also excludes terms that are matched by child
+sections of ${node}. Terms with the same primary title are all included. It
+is the responsibility of the caller to merge these.
+
+The results are not sorted. The output is a result tree fragment. To use these
+results, call #{exsl:node-set} on them.
+-->
+<xsl:template name="mal.gloss.terms">
+ <xsl:param name="node" select="."/>
+ <xsl:for-each select="$mal.cache//mal:info/gloss:term">
+ <xsl:variable name="term" select="."/>
+ <xsl:variable name="exclude">
+ <xsl:for-each select="$node/ancestor-or-self::*/mal:info/gloss:match">
+ <xsl:call-template name="mal.gloss.match">
+ <xsl:with-param name="match" select="."/>
+ <xsl:with-param name="term" select="$term"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ <xsl:for-each select="$node/mal:section/mal:info/gloss:match">
+ <xsl:variable name="secmatch">
+ <xsl:call-template name="mal.gloss.match">
+ <xsl:with-param name="match" select="."/>
+ <xsl:with-param name="term" select="$term"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:if test="$secmatch = ''">
+ <xsl:text>x</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:if test="$exclude = ''">
+ <xsl:copy>
+ <xsl:attribute name="gloss:id">
+ <xsl:value-of select="generate-id(.)"/>
+ </xsl:attribute>
+ <xsl:copy-of select="node()"/>
+ </xsl:copy>
+ </xsl:if>
+ </xsl:for-each>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xslt/mallard/html/Makefile.am b/xslt/mallard/html/Makefile.am
index 054ca9c..4a0898c 100644
--- a/xslt/mallard/html/Makefile.am
+++ b/xslt/mallard/html/Makefile.am
@@ -3,6 +3,7 @@ xsldir=$(datadir)/yelp-xsl/xslt/mallard/html
xsl_DATA = \
mal2html-block.xsl \
mal2html-facets.xsl \
+ mal2html-gloss.xsl \
mal2html-inline.xsl \
mal2html-links.xsl \
mal2html-list.xsl \
diff --git a/xslt/mallard/html/mal2html-gloss.xsl b/xslt/mallard/html/mal2html-gloss.xsl
new file mode 100644
index 0000000..fc6660d
--- /dev/null
+++ b/xslt/mallard/html/mal2html-gloss.xsl
@@ -0,0 +1,112 @@
+<?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.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+ xmlns:mal="http://projectmallard.org/1.0/";
+ xmlns:cache="http://projectmallard.org/cache/1.0/";
+ xmlns:gloss="http://projectmallard.org/experimental/gloss/";
+ xmlns:exsl="http://exslt.org/common";
+ xmlns:str="http://exslt.org/strings";
+ xmlns="http://www.w3.org/1999/xhtml";
+ exclude-result-prefixes="mal cache gloss exsl str"
+ version="1.0">
+
+<!--!!==========================================================================
+Mallard to HTML - Glossaries
+Support the Mallard Glossary extension.
+
+This stylesheet contains templates and supporting JavaScript to support the
+Mallard Glossary extension in HTML.
+-->
+
+
+<!--**==========================================================================
+mal2html.gloss.terms
+Display the glossary terms for a page or section.
+$node: The glossary #{page} or #{section} to output terms for.
+
+This template shows the glossary terms for a page or section. It collects the
+terms with the *{mal.gloss.terms} template, sorts them, and merges terms with
+the same primary title. Terms that are not defined in the same page as ${node}
+include a link to their defining page.
+-->
+<xsl:template name="mal2html.gloss.terms">
+ <xsl:param name="node" select="."/>
+ <xsl:variable name="pageid" select="$node/ancestor-or-self::mal:page[1]/@id"/>
+ <xsl:variable name="terms_">
+ <xsl:call-template name="mal.gloss.terms">
+ <xsl:with-param name="node" select="$node"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="terms" select="exsl:node-set($terms_)/*"/>
+ <xsl:if test="count($terms) > 0">
+ <dl class="list gloss-list">
+ <xsl:for-each select="$terms">
+ <xsl:sort select="string(mal:title)"/>
+ <xsl:variable name="term" select="."/>
+ <xsl:for-each select="$mal.cache">
+ <xsl:variable name="primaryid" select="generate-id(
+ key('mal.gloss.key', $term/mal:title[1])
+ [generate-id(.) = $terms/@gloss:id][1])"/>
+ <xsl:if test="not($primaryid = $terms/@gloss:id) or $term/@gloss:id = $primaryid">
+ <dt class="gloss-term">
+ <xsl:apply-templates mode="mal2html.inline.mode"
+ select="$term/mal:title/node()"/>
+ </dt>
+ <xsl:variable name="defs" select="key('mal.gloss.key', $term/mal:title[1])
+ [generate-id(.) = $terms/@gloss:id]"/>
+ <xsl:for-each select="$defs">
+ <xsl:sort data-type="number" select="number(boolean(*[not(self::mal:title)]))"/>
+ <xsl:sort data-type="number" select="number(not(ancestor::mal:page[1]/@id = $pageid))"/>
+ <xsl:variable name="termpageid" select="ancestor::mal:page[1]/@id"/>
+ <xsl:if test="not($termpageid = $pageid)">
+ <dd class="gloss-link">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:call-template name="mal.link.target">
+ <xsl:with-param name="xref" select="$termpageid"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ <xsl:attribute name="title">
+ <xsl:call-template name="mal.link.tooltip">
+ <xsl:with-param name="xref" select="$termpageid"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ <xsl:call-template name="mal.link.content">
+ <xsl:with-param name="node" select="."/>
+ <xsl:with-param name="xref" select="$termpageid"/>
+ <xsl:with-param name="role" select="'gloss:page'"/>
+ </xsl:call-template>
+ </a>
+ </dd>
+ </xsl:if>
+ <xsl:if test="*[not(self::mal:title)]">
+ <dd class="gloss-def">
+ <xsl:apply-templates mode="mal2html.block.mode"
+ select="*[not(self::mal:title)]"/>
+ </dd>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:for-each>
+ </dl>
+ </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xslt/mallard/html/mal2html-page.xsl b/xslt/mallard/html/mal2html-page.xsl
index c590995..dbf3ea1 100644
--- a/xslt/mallard/html/mal2html-page.xsl
+++ b/xslt/mallard/html/mal2html-page.xsl
@@ -438,6 +438,9 @@ REMARK: Describe this template
</xsl:call-template>
</xsl:if>
</xsl:if>
+ <xsl:if test="$type = 'gloss:glossary'">
+ <xsl:call-template name="mal2html.gloss.terms"/>
+ </xsl:if>
<xsl:if test="$type = 'facets'">
<xsl:call-template name="mal2html.facets.links"/>
</xsl:if>
@@ -779,6 +782,25 @@ div.facet input {
vertical-align: middle;
margin: 0;
}
+dt.gloss-term {
+ font-weight: bold;
+ color: </xsl:text><xsl:value-of select="$color.text_light"/><xsl:text>;
+}
+dd.gloss-link {
+ margin: 0 0.2em 0 0.2em;
+ border-</xsl:text><xsl:value-of select="$left"/><xsl:text>: solid 4px </xsl:text>
+ <xsl:value-of select="$color.blue_border"/><xsl:text>;
+ padding-</xsl:text><xsl:value-of select="$left"/><xsl:text>: 1em;
+}
+dd.gloss-def {
+ margin: 0 0.2em 0 0.2em;
+ border-</xsl:text><xsl:value-of select="$left"/><xsl:text>: solid 4px </xsl:text>
+ <xsl:value-of select="$color.gray_border"/><xsl:text>;
+ padding-</xsl:text><xsl:value-of select="$left"/><xsl:text>: 1em;
+}
+dd.gloss-def + dd.gloss-link {
+ margin-top: 1em;
+}
</xsl:text>
<xsl:if test="$mal2html.editor_mode">
<xsl:text>
diff --git a/xslt/mallard/html/mal2xhtml.xsl b/xslt/mallard/html/mal2xhtml.xsl
index 4655090..0724c96 100644
--- a/xslt/mallard/html/mal2xhtml.xsl
+++ b/xslt/mallard/html/mal2xhtml.xsl
@@ -35,6 +35,7 @@ REMARK: Describe this module
<xsl:import href="../../common/html.xsl"/>
<xsl:import href="../../common/utils.xsl"/>
+<xsl:import href="../common/mal-gloss.xsl"/>
<xsl:import href="../common/mal-if.xsl"/>
<xsl:import href="../common/mal-link.xsl"/>
@@ -43,6 +44,7 @@ REMARK: Describe this module
<xsl:include href="mal2html-block.xsl"/>
<xsl:include href="mal2html-facets.xsl"/>
+<xsl:include href="mal2html-gloss.xsl"/>
<xsl:include href="mal2html-inline.xsl"/>
<xsl:include href="mal2html-links.xsl"/>
<xsl:include href="mal2html-list.xsl"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]