2017-07-06 5 views
0

Ich tippe ein Buch mit mathematischen Formeln, die in MathML geschrieben wurden. Das Buch hat eine "Haupt" XML-Datei, die alle Kapitel Dateien wie diese enthält:DocBook 5, Hinzufügen (MathML) Namespace zu HTML-Ausgabe?

<?xml version="1.0" encoding="utf-8"?> 
<book xmlns="http://docbook.org/ns/docbook" 
     xmlns:xi="http://www.w3.org/2001/XInclude" 
     version="5.1" 
     xml:lang="en"> 
    <title>Some title</title> 
    <xi:include href="intro.xml"/> 
</book> 

Und intro.xml geht als

<?xml version="1.0" encoding="utf-8"?> 
<chapter xml:id="ch-intro" xmlns:m="http://www.w3.org/1998/Math/MathML"> 
    <title>Introduction</title> 
    <para>Some text 
    <inlineequation> 
    <m:math><m:msqrt><m:mi>a</m:mi></m:msqrt></m:math> 
    </inlineequation> 
    Some other text. 
    </para> 
</chapter> 

Das ist etwas wie

<p>Some text 
<m:math xmlns:m="http://www.w3.org/1998/Math/MathML"> 
    <m:msqrt><m:mi>a</m:mi></m:msqrt> 
</m:math> 
Some other text.</p> 

I produziert haben Sie eine Anpassungsschicht XSLT über dem HTML XSLT von Docbook-XSL, um MathJax zu laden:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:m="http://www.w3.org/1998/Math/MathML" 
       version="1.0"> 
    <xsl:import href="docbook-xsl-nons-snapshot/html/docbook.xsl"/> 
    <!-- Add MathJax <script> tags to document <head> --> 
    <xsl:template name="user.head.content"> 
    <script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=MML_CHTML"></script> 
    </xsl:template> 
</xsl:stylesheet> 

Und das funktioniert in dem Sinne, dass es das <script> Tag zu hinzufügt, aber MathJax rendert die Formel nicht, da es nicht funktioniert, wenn der MathML-Namespace auf <math> selbst ist. Der Namespace muss zu gehen.

Also meine Frage ist, wie soll ich die XSLT-Anpassungsschicht schreiben, um xmlns:m="http://www.w3.org/1998/Math/MathML" zu dem generierten -Tag hinzuzufügen?

Antwort

1

Was passiert, wenn Sie die Vorlage unter überschreiben, indem sie in der Hauptsheet-Modul setzen:

<xsl:template match="*" mode="process.root"> 
    <xsl:variable name="doc" select="self::*"/> 

    <xsl:call-template name="user.preroot"/> 
    <xsl:call-template name="root.messages"/> 

    <html> 
    <xsl:call-template name="root.attributes"/> 
    <head> 
     <xsl:call-template name="system.head.content"> 
     <xsl:with-param name="node" select="$doc"/> 
     </xsl:call-template> 
     <xsl:call-template name="head.content"> 
     <xsl:with-param name="node" select="$doc"/> 
     </xsl:call-template> 
     <xsl:call-template name="user.head.content"> 
     <xsl:with-param name="node" select="$doc"/> 
     </xsl:call-template> 
    </head> 
    <body> 
     <xsl:call-template name="body.attributes"/> 
     <xsl:call-template name="user.header.content"> 
     <xsl:with-param name="node" select="$doc"/> 
     </xsl:call-template> 
     <xsl:apply-templates select="."/> 
     <xsl:call-template name="user.footer.content"> 
     <xsl:with-param name="node" select="$doc"/> 
     </xsl:call-template> 
    </body> 
    </html> 
    <xsl:value-of select="$html.append"/> 

    <!-- Generate any css files only once, not once per chunk --> 
    <xsl:call-template name="generate.css.files"/> 
</xsl:template> 

Da das Modul die MathML Namespace-Deklaration hat ich erwarten würde, dass das erzeugte Wurzelelement es auch hat.

+0

Das funktioniert super! Es ließ auch jedes nicht das Attribut xmlns: m haben. Vielen Dank! – MetroWind