473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MathML weirdness

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:output 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>

May 17 '06 #1
3 1388
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.

May 17 '06 #2
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

May 17 '06 #3
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.
May 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joachim Spoerhase | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, does anybody know a good WYSIWYG MathML Equation Editor for Linux? Many thanks in advance Joachim Spoerhase -----BEGIN PGP...
2
by: Florian Huber | last post by:
Hello! i've got a Problem: I'd like to build a website, which contains HTML and MathML, but it should be readable for most of the site visitors. I know about the ways mentioned at the...
2
by: Jon Thackray | last post by:
I'm trying to use the MathML DTD and stylesheets, but get some problems with xmlns attributes. If I do something like <math xmlns="http://..."> .... </math> then xmllint and xalan in...
4
by: Jon Thackray | last post by:
I'm trying to build some mathml for a paper. I've got the mathml2 dtd, and the style sheets also from the canonical website http://www.w3.org/Math/. But I'm having some trouble. I've input the...
7
by: DKM | last post by:
I need an equivalent for the following: document.getElementById('equation').update(); from Mathplayer to use it in Mozilla based browser. When I change any text node, the page updates just...
1
by: Stefan Behnel | last post by:
Hi! I was looking for an implementation of a parser/model/serializer for Content MathML in Python. Does anyone know about something useful? I need to work with math expressions...
3
by: Michel de Becdelièvre | last post by:
I have some *performance* trouble reading MathML files in my application (in ASP.Net). - I have small MathML files (2-3k) as input - as (almost) all MathML files these use entities. I have no...
3
by: dan_andrews | last post by:
<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" > <html xmlns="http://www.w3.org/1999/xhtml">...
3
by: BakedBean | last post by:
Hi, This is probably really simple, but I've only just been asked to look at this and I've spent a full day trying to get it to work, so any help will be very gratefully received! At present...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.