OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] include MathML files with the help of XSL


Here is my test setup:

DocBook 4.4 XML file:


<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="">HTML5_MathML.xsl" type="text/xsl"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "docbookV4.4/docbookx.dtd" []>
<book xmlns:xi="http://www.w3.org/2001/XInclude">
    <title/>
    <chapter>
        <title/>
        <para>
            <inlineequation id="Eq_0005">
                <inlinemediaobject>
                  <imageobject>
                    <imagedata fileref="math/Eq_0005.gif"/>
                  </imageobject>
                </inlinemediaobject>
            </inlineequation>
        </para>
    </chapter>
</book>


The XSLT file (HTML5_MathML.xsl):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="utf-8" indent="yes" />

    <xsl:template match="inlineequation">
        <xsl:variable name="id" select="@id"/>
        <xsl:variable name="mathml" select="concat($id, '.xml')"/>
        <xsl:apply-templates select="document($mathml,.)/*"/>
    </xsl:template>

 
    <xsl:template match="/">
        <xsl:text disable-output-escaping='yes'></xsl:text>
            <html>
                <body>
                    <xsl:apply-templates/>
                </body>
            </html>
    </xsl:template>

</xsl:stylesheet>


MathML file (Eq_0005.xml):

    <math xmlns="http://www.w3.org/1998/Math/MathML">
      <mrow>
        <msup><mi>a</mi><mn>2</mn></msup>
        <mo>+</mo>
        <msup><mi>b</mi><mn>2</mn></msup>
        <mo>=</mo>
        <msup><mi>c</mi><mn>2</mn></msup>
      </mrow>
    </math>


Expected result:

<!doctype html>
  <html>
  <head>
   <meta charset="UTF-8">
  </head>
  <body>
    <math xmlns="http://www.w3.org/1998/Math/MathML">
      <mrow>
        <msup><mi>a</mi><mn>2</mn></msup>
        <mo>+</mo>
        <msup><mi>b</mi><mn>2</mn></msup>
        <mo>=</mo>
        <msup><mi>c</mi><mn>2</mn></msup>
      </mrow>
    </math>

  </body>
</html>

Obtained result: (by opening the DocBook XML file in FireFox)


<html>
<body> x ( t ) = R e [ A ⋅ e j ( ω 0 ⋅ t + Φ ) ] </body>
</html>

Problem 1:
All of the MathML XML elements are missing.

Problem 2:
You wrote something about DocBook MML template match and I couldn't really understand what should I do with that:
>>> You might want to add some error checking to this code. You can use
>>> xsl:apply-templates here because the DocBook stylesheets already have
>>> templates matching on MathML elements, and they just copy the elements
>>> through to the output. In html/math.xsl you will find:
>>>
>>> <xsl:template match="mml:*"
>>> xmlns:mml="http://www.w3.org/1998/Math/MathML">
>>> <xsl:copy>
>>> <xsl:copy-of select="@*"/>
>>> <xsl:apply-templates/>
>>> </xsl:copy>
>>> </xsl:template>


It seems to me really usable (just copying the MathML objects), but in my files, there are no mml namespace given.

2012/6/14 Zoltán János Jánosi <jazoja4@gmail.com>:
> OK, I'll do.
>
> 2012/6/14 Bob Stayton <bobs@sagehill.net>:
>> OK.  If it works, please post your reply to the mailing list so it gets into
>> the list archive.
>>
>>
>> Bob Stayton
>> Sagehill Enterprises
>> bobs@sagehill.net
>>
>>
>> ----- Original Message ----- From: "Zoltán János Jánosi" <jazoja4@gmail.com>
>> To: "Bob Stayton" <bobs@sagehill.net>
>> Sent: Thursday, June 14, 2012 2:09 PM
>>
>> Subject: Re: [docbook-apps] include MathML files with the help of XSL
>>
>>
>> Thanx Bob, you are right about what I originally wanted.
>> Thanx for the answer, soon I'll try it!
>>
>> 2012/6/14 Bob Stayton <bobs@sagehill.net>:
>>>
>>> I think the requestor wanted to do this without modifying the XML files to
>>> add the references to the MathML files:
>>>
>>>
>>>> dynamically pull in MathML files (by their ID)
>>>
>>>
>>>
>>> That's why he was trying to use XInclude in XSL. However, XInclude cannot
>>> be used inside an XSLT stylesheet because XSLT processors do not recognize
>>> it or process it. The XInclude step is performed when the files are parsed
>>> by the XML parser, before the stylesheet sees the XML.
>>>
>>> But a stylesheet can use the XSLT document() function to open and include
>>> other content. Something like this would work
>>>
>>> <xsl:template match="inlineequation">
>>> <xsl:variable name="id" select="@id"/>
>>> <xsl:variable name="mathml" select="concat($id, '.xml')"/>
>>> <xsl:apply-templates select="document($mathml,.)/*"/>
>>> </xsl:template>
>>>
>>> You might want to add some error checking to this code. You can use
>>> xsl:apply-templates here because the DocBook stylesheets already have
>>> templates matching on MathML elements, and they just copy the elements
>>> through to the output. In html/math.xsl you will find:
>>>
>>> <xsl:template match="mml:*"
>>> xmlns:mml="http://www.w3.org/1998/Math/MathML">
>>> <xsl:copy>
>>> <xsl:copy-of select="@*"/>
>>> <xsl:apply-templates/>
>>> </xsl:copy>
>>> </xsl:template>
>>>
>>>
>>> Bob Stayton
>>> Sagehill Enterprises
>>> bobs@sagehill.net
>>>
>>>
>>> ----- Original Message ----- From: Carlos Araya
>>> To: Zoltán János Jánosi
>>> Cc: docbook-apps@lists.oasis-open.org
>>> Sent: Wednesday, June 13, 2012 9:37 AM
>>> Subject: Re: [docbook-apps] include MathML files with the help of XSL
>>>
>>>
>>>
>>> The first thing I see is that you need to include the mathml namespace in
>>> your customization layer
>>>
>>> <xsl:stylesheet
>>> version="1.0"
>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>> xmlns:mml="http://www.w3.org/1998/Math/MathML"
>>> xmlns:xi="http://www.w3.org/2001/XInclude">
>>>
>>> Elements for the MathML namespace should be prefixed with the prefix you
>>> chose (mml in the case above). Same thing with the XIncllude elements,
>>> they
>>> have to be on their own namespace (xi)
>>>
>>> Each ID has to be unique. Otherwise when inserting the MathML equation the
>>> XSLT processor will throw an error for duplicate IDs
>>>
>>> Using the code you provide below I would do something like this:
>>>
>>> <inlineequation id="Eq_0005">
>>> <inlinemediaobject>
>>> <imageobject>
>>> <imagedata fileref="math/Eq_0005.gif"/>
>>> </imageobject>
>>> <textobject>
>>> <xi:include href="">>>> </textobject>
>>> </inlinemediaobject>
>>> </inlineequation>
>>>
>>> The processor will use the first element that it can handle (as explained
>>> in
>>> http://docbook.org/tdg51/en/html/inlinemediaobject.html) so the order in
>>> which you put them may be important.
>>>
>>> Using xincludes may also change the way in which you process your
>>> documents.
>>> Look at Bob Stayton's book for how to pre-process your document with
>>> xincluded content (http://www.sagehill.net/docbookxsl/Xinclude.html)
>>>
>>>
>>> On Wed, Jun 13, 2012 at 1:52 AM, Zoltán János Jánosi <jazoja4@gmail.com>
>>> wrote:
>>>
>>> Hi all!
>>>
>>> My question:
>>> Is there any way (with XSLT) to dynamically pull in MathML files (by their
>>> ID) and put them into the XML/HTML files?
>>>
>>> The situation is the following:
>>>
>>> I have a DocBook 4.4 XML file with equation objects in it.
>>> Every equation object has a unique ID.
>>> For every equation ID belongs to 2 files, one MathML 2.0 XML file and a
>>> graphics version.
>>> Both filename is constructed from the equation ID+extension.
>>> The graphics version is linked by the imagedata tag.
>>>
>>> The source equation looks like this: (DocBook 4.4)
>>> <para>
>>> <inlineequation id="Eq_0005">
>>> <inlinemediaobject>
>>> <imageobject>
>>> <imagedata fileref="math/Eq_0005.gif"/>
>>> </imageobject>
>>> </inlinemediaobject>
>>> </inlineequation>
>>> <para>
>>>
>>> I'd like to dynamically transform the equation object to include the
>>> MathML
>>> version rather than the graphics version. I tried to transform the DocBook
>>> document into XHTML and HTML5, and use xinclude to include the MathML XML
>>> files, but didn't succeed yet.
>>> It should look something like this at the end: (I think)
>>> <p>
>>> <math>
>>> <mrow>
>>> <mi>a</mi>
>>> <mo>&InvisibleTimes;</mo>
>>> <msup>
>>> ...
>>> </math>
>>> </p>
>>>
>>> What I have tried yet:
>>> Here is a simple XSLT to get the equation ID:
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <xsl:stylesheet version="1.0"
>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>>> <xsl:output method="html"/>
>>> <xsl:template match="inlineequation">
>>> The ID of equation is <xsl:value-of select="@id"/>
>>> </xsl:template>
>>> </xsl:stylesheet>
>>>
>>> Then I tried to use the xinclude and put into the XSLT but none of them
>>> seemed to work.
>>>
>>> Any ideas appreciated.
>>> Thanx in advance!
>>
>>
>>



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]