MathML weirdness

Discussion in 'XML' started by Fred, May 17, 2006.

  1. Fred

    Fred Guest

    I'm experimenting with MathML, and have run into difficulty.

    Given the simple XML:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE component SYSTEM "mathml2.dtd">
    <mathDisplay>
    <math>
    <msub>
    <mi>z</mi>
    <mn>2</mn>
    </msub>
    </math>
    </mathDisplay>
    and the simple XSLT stylesheet given below, I expect the output
    <?xml version="1.0" encoding="utf-8"?>
    <mathML><xmathDisplay><xmath><xmsub><xmi>z</xmi>
    <xmn>2</xmn></xmsub></xmath></xmathDisplay></mathML>
    Instead, I get
    <?xml version="1.0" encoding="utf-8"?>
    <mathML><xmathDisplay>z2</xmathDisplay></mathML>
    I get the results I expect if I delete the DOCTYPE line from the xml
    file.

    I can also get the results I expect if I change the names of the MathML
    elements to, say, <a>, <b>, <c>, ...

    In what way is the behavior of an XSLT stylesheet dependent upon the
    details
    of an XML document's doctype?

    Thanks!

    The spreadsheet:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:eek:utput method="xml" encoding="utf-8"/>
    <xsl:template match="/">
    <mathML>
    <xsl:apply-templates/>
    </mathML>
    </xsl:template>
    <xsl:template match="mathDisplay">
    <xmathDisplay>
    <xsl:apply-templates/>
    </xmathDisplay>
    </xsl:template>
    <xsl:template match="math">
    <xmath>
    <xsl:apply-templates/>
    </xmath>
    </xsl:template>
    <xsl:template match="msub">
    <xmsub>
    <xsl:apply-templates/>
    </xmsub>
    </xsl:template>
    <xsl:template match="mi">
    <xmi>
    <xsl:apply-templates/>
    </xmi>
    </xsl:template>
    <xsl:template match="mn">
    <xmn>
    <xsl:apply-templates/>
    </xmn>
    </xsl:template>
    </xsl:stylesheet>
     
    Fred, May 17, 2006
    #1
    1. Advertising

  2. Try it without specifying the DTD. If that produces the right output,
    check whether the MathML DTD is automatically setting default namespaces
    for those elements. If so, your stylesheet has to be made namespace-aware.
     
    Joe Kesselman, May 17, 2006
    #2
    1. Advertising

  3. Fred

    Fred Guest

    Adding xmlns:m="http://www.w3.org/1998/Math/MathML" to xsl:stylesheet
    and prefixing all the MathML element names in the xsl:templates with
    "m:" worked. Thanks!

    I don't quite understand why it's necessary to specify the namespace if
    one isn't going to be using the prefixed form of the element names in
    the XML documents ... nor does a quick scan of Kay's book help. Could
    you point me to an explanation of this phenomenon?

    Thanks again,
    Fred
     
    Fred, May 17, 2006
    #3
  4. Fred wrote:
    > I don't quite understand why it's necessary to specify the namespace if
    > one isn't going to be using the prefixed form of the element names in
    > the XML documents


    The meaningful thing isn't the prefix, or lack of one -- it's whether
    the element and/or attribute is bound to a namespace. In your case, the
    DTD is indeed asserting such a binding, via a default namespace
    declaration (xmlns=).

    XPath, and XSLT, are always namespace-aware. This means all element and
    attribute names they refer to have to be in the correct namespace, or
    they won't match. Since XPath 1.0 has no concept of default namespaces
    in its own syntax, that means that the only way to refer to namespaced
    names is to use a prefix bound to the correct namespace.

    Don't confuse syntax and semantics. Prefixes are syntax. Namespaces are
    the semantic they represent.
     
    Joe Kesselman, May 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVyZW15?=

    MathML

    =?Utf-8?B?SmVyZW15?=, May 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    747
    =?Utf-8?B?RG91ZyBIb2xsYW5k?=
    May 9, 2004
  2. DKM
    Replies:
    1
    Views:
    532
  3. Sam Hwang

    MathML in Java

    Sam Hwang, Sep 9, 2005, in forum: Java
    Replies:
    1
    Views:
    1,376
    Andrew Thompson
    Sep 9, 2005
  4. oulan bator

    XMLBeans MathML presentation

    oulan bator, Dec 14, 2005, in forum: Java
    Replies:
    1
    Views:
    421
    oulan bator
    Dec 14, 2005
  5. steve
    Replies:
    4
    Views:
    535
    Brian van den Broek
    Mar 13, 2005
Loading...

Share This Page