Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

Re: MathML 2 ascii?

by mirod (Canon)
on Jan 27, 2005 at 03:49 UTC ( [id://425505]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to MathML 2 ascii?

Below is how I would do it.

It should be extensible to handle other units. It assumes apply is only used with 2 arguments, but this shouldn't be a problem, if it is used with more I would assume that it is for multiplication, which doesn't need any symbol to be applied.

If I were you I would first create a version that would just output the unit -> ascii conversion, and run it on all documents, or on a set of documents. Something like removing the twig_print_outside_roots, instead of printing the content of unit store it in a hash $_->sprint => $_->text, and dump the content of that hash once you're done. This will give you all units in the document, so you can check the transformation. If you are not happy with the results and working at XML level is too much of a pain you can also add a final transformation there, with a simple hash initial_result => what_you_want.

BTW are you really limited to pure ascii? Displaying J/m² could be a nice touch.

#!/usr/bin/perl -w use strict; use XML::Twig; my %unit2symbol= ( joule => 'J', meter => 'm'); XML::Twig->new( twig_roots => { unit => sub { print $_->text } }, twig_handlers => { divide => sub { $_->set_text( '/') +}, ci => sub { $_->set_text( $unit +2symbol{$_->text}); }, apply => sub { $_->child( 0)->move +( after => $_->child( 1)); }, }, twig_print_outside_roots => 1, ) ->parse( \*DATA); __DATA__ <doc> <p>10 <unit> <math> <apply> <divide/> <ci>joule</ci> <apply> <power/> <ci>meter</ci> <cn>2</cn> </apply> </apply> </math> </unit></p> </doc>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://425505]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.