[yelp-xsl: 5/5] mal2html-svg: Inline SVG into non-XML HTML5, instead of <object>
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp-xsl: 5/5] mal2html-svg: Inline SVG into non-XML HTML5, instead of <object>
- Date: Tue, 5 May 2015 02:48:50 +0000 (UTC)
commit 6b4a3b118fbedfe540573104f50d1bcd851e686f
Author: Shaun McCance <shaunm gnome org>
Date: Mon May 4 19:03:23 2015 -0400
mal2html-svg: Inline SVG into non-XML HTML5, instead of <object>
xslt/common/html.xsl | 26 ++++++++++++++++++-
xslt/mallard/html/mal2html-svg.xsl | 46 ++++++++++++++----------------------
xslt/mallard/html/mal2html.xsl | 4 ++-
3 files changed, 45 insertions(+), 31 deletions(-)
---
diff --git a/xslt/common/html.xsl b/xslt/common/html.xsl
index fca4777..a29a38b 100644
--- a/xslt/common/html.xsl
+++ b/xslt/common/html.xsl
@@ -113,8 +113,8 @@ using #{xsl:element}.
<!--@@==========================================================================
html.mathml.namespace
-The XML namespace for the output document.
-:Revision:version="3.8" date="2012-11-13" status="final"
+The XML namespace for MathML in the output document.
+:Revision:version="3.18" date="2015-05-04" status="final"
This parameter specifies the XML namespace for MathML in output documents. It
will be set automatically based on the ${html.xhtml} parameter, either to the
@@ -134,6 +134,28 @@ parameter when using #{xsl:element}.
<!--@@==========================================================================
+html.svg.namespace
+The XML namespace for SVG in the output document.
+:Revision:version="3.18" date="2015-05-04" status="final"
+
+This parameter specifies the XML namespace for SVG in output documents. It
+will be set automatically based on the ${html.xhtml} parameter, either to the
+SVG namespace namespace, or to the empty namespace. Stylesheets can use this
+parameter when using #{xsl:element}.
+-->
+<xsl:variable name="html.svg.namespace">
+ <xsl:choose>
+ <xsl:when test="$html.xhtml">
+ <xsl:value-of select="'http://www.w3.org/2000/svg'"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text></xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+
+<!--@@==========================================================================
html.extension
The filename extension for all output files.
:Revision:version="1.0" date="2010-05-25" status="final"
diff --git a/xslt/mallard/html/mal2html-svg.xsl b/xslt/mallard/html/mal2html-svg.xsl
index 564b23b..31fb735 100644
--- a/xslt/mallard/html/mal2html-svg.xsl
+++ b/xslt/mallard/html/mal2html-svg.xsl
@@ -35,12 +35,14 @@ in %{mal2html.svg.mode}.
<!--%%==========================================================================
mal2html.svg.mode
-Output SVG and handle Mallard extension.
-:Revision: version="1.0" date="2010-06-04" status="final"
+Output SVG and handle Mallard extensions.
+:Revision: version="3.18" date="2015-05-04" status="final"
This mode is used for processing SVG embedded into Mallard documents. For most
-types of SVG content, it simply copies the input directly. It does check for
-certain Mallard extensions, for example to use the Mallard linking mechanism.
+types of SVG content, it simply copies the input directly, except it outputs
+the SVG in a way that allows the namespace to stripped for non-XML output. It
+checks for Mallard linking using the #{mal:xref} attribute and transforms this
+to an XLink #{xlink:href} attribute.
-->
<xsl:template mode="mal2html.svg.mode" match="svg:*">
<xsl:choose>
@@ -57,23 +59,24 @@ certain Mallard extensions, for example to use the Mallard linking mechanism.
<xsl:with-param name="role" select="'text'"/>
</xsl:call-template>
</xsl:variable>
- <svg:a xlink:href="{$target}" xlink:show="replace"
- xlink:title="{$title}" target="_top">
- <xsl:copy>
- <xsl:for-each select="@*">
- <xsl:copy/>
+ <svg:a xlink:href="{$target}" xlink:title="{$title}">
+ <xsl:element name="{local-name(.)}" namespace="{$html.svg.namespace}">
+ <xsl:for-each select="@*[
+ namespace-uri(.)!='http://projectmallard.org/1.0/' and
+ namespace-uri(.)!='http://www.w3.org/1999/xlink']">
+ <xsl:copy-of select="."/>
</xsl:for-each>
<xsl:apply-templates mode="mal2html.svg.mode" select="node()"/>
- </xsl:copy>
+ </xsl:element>
</svg:a>
</xsl:when>
<xsl:otherwise>
- <xsl:copy>
- <xsl:for-each select="@*">
- <xsl:copy/>
+ <xsl:element name="{local-name(.)}" namespace="{$html.svg.namespace}">
+ <xsl:for-each select="@*[namespace-uri(.)!='http://projectmallard.org/1.0/']">
+ <xsl:copy-of select="."/>
</xsl:for-each>
<xsl:apply-templates mode="mal2html.svg.mode" select="node()"/>
- </xsl:copy>
+ </xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
@@ -107,20 +110,7 @@ certain Mallard extensions, for example to use the Mallard linking mechanism.
</xsl:if>
</xsl:with-param>
</xsl:call-template>
- <xsl:choose>
- <xsl:when test="$html.xhtml">
- <xsl:apply-templates mode="mal2html.svg.mode" select="."/>
- </xsl:when>
- <xsl:otherwise>
- <object data="{$id}.svg" type="image/svg+xml">
- <xsl:copy-of select="@width"/>
- <xsl:copy-of select="@height"/>
- </object>
- <exsl:document href="{$id}.svg">
- <xsl:apply-templates mode="mal2html.svg.mode" select="."/>
- </exsl:document>
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:apply-templates mode="mal2html.svg.mode" select="."/>
</div>
</xsl:if>
</xsl:template>
diff --git a/xslt/mallard/html/mal2html.xsl b/xslt/mallard/html/mal2html.xsl
index abcd281..70dbdb3 100644
--- a/xslt/mallard/html/mal2html.xsl
+++ b/xslt/mallard/html/mal2html.xsl
@@ -17,7 +17,8 @@ along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
- exclude-result-prefixes="html mml"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ exclude-result-prefixes="html mml svg"
version="1.0">
<!--!!==========================================================================
@@ -38,5 +39,6 @@ sets @{html.xhtml} to #{false} and @{mal.if.target} to #{'target:html'}.
<xsl:namespace-alias stylesheet-prefix="html" result-prefix="#default"/>
<xsl:namespace-alias stylesheet-prefix="mml" result-prefix="#default"/>
+<xsl:namespace-alias stylesheet-prefix="svg" result-prefix="#default"/>
</xsl:stylesheet>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]