CSS or CSS2 and XML in Java

O

oulan bator

hi,

is there a a way to read a styled (by CSS) XML file, and get it fully
substituted, all in one (or two) step ?
Or have I to do it myself ?

I'm trying to read MathML-presentation documents, that can come with a
css (either embedded, or linked in). I would like to have the file
read, and all styled attribute set following CSS rules.

Is it possible ?

thx
 
R

Rhino

oulan bator said:
hi,

is there a a way to read a styled (by CSS) XML file, and get it fully
substituted, all in one (or two) step ?
Or have I to do it myself ?

I'm trying to read MathML-presentation documents, that can come with a
css (either embedded, or linked in). I would like to have the file
read, and all styled attribute set following CSS rules.

Is it possible ?
I don't think I really understand your question so I don't know if this will
help.

My memory on this is very hazy but I believe the recommended approach for
controlling the appearance of XML is to use XSL, not CSS. If you want to
apply an XSL stylesheet to XML very easily - once you've actually written
the XSL - you can do this; it's not Java but it works!

=======================================
<html>

<body><script type="text/javascript">// Load XML

var xml = new ActiveXObject("Microsoft.XMLDOM")

xml.async = false

xml.load("Foo.log.xml")

// Load XSL

var xsl = new ActiveXObject("Microsoft.XMLDOM")

xsl.async = false

xsl.load("JavaLogger.xsl")

// Transform

document.write(xml.transformNode(xsl))</script>

</body>

</html>

=======================================

The name of the XML file in this example is 'Foo.log.xml' and the name of
the XSL file is 'JavaLogger.xsl'.

This small script is real code that I wrote myself for a project a while
back.

Rhino
 
O

oulan bator

hi,

thanks, but that's not really what I need.

I'm working in a standalone application. I wan't to show a
MathML-presentation (for the moment this standard piece of XML, but I'm
still interested in any kind of XML).
If the MathML XML source is styled (through processing-instruction for
instance), how can I apply CSS rules to this document ! I'd like to
avoid doing-it by myself.

I've heard about SAC, but there are too few implementations.
 
O

Oliver Wong

oulan bator said:
hi,

is there a a way to read a styled (by CSS) XML file, and get it fully
substituted, all in one (or two) step ?

I strongly doubt it. Perhaps in a couple hundred steps.
Or have I to do it myself ?

Very likely.
I'm trying to read MathML-presentation documents, that can come with a
css (either embedded, or linked in). I would like to have the file
read, and all styled attribute set following CSS rules.

Is it possible ?

See http://www.w3schools.com/xml/xml_display.asp particularly the part that
says:

<quote>
Note: Formatting XML with CSS is NOT the future of how to style XML
documents. XML document should be styled by using the W3C's XSL standard!
</quote>

It's possible, but not the recommended way of doing things.
Incidentally, I don't think Java has built in support for XSL either.

- Oliver
 
R

Roedy Green

I'm trying to read MathML-presentation documents, that can come with a
css (either embedded, or linked in). I would like to have the file
read, and all styled attribute set following CSS rules.

Is it possible ?

I would say no simply because you can describe fancy layouts in CSS
for which there is no HTML equivalent.

You might though be able to roughly express it.

Another approach might be to see if you can convert your CSS to PDF
which can be viewed without CSS.

If you generate your web pages it may be easier to simply generate two
versions.
 
O

oulan bator

hi,

I don't think CSS is dead, and that XSL stands right for what I need to
do. I know how to handle XSL in java (it is built in since 1.4 IMHO)

I am not generating any web page. I want to get some "raw"
MathML-presentation and and present beautified MathML presentation
(like color attribute for some elements etc...) as described in a CSS
file.

it is possible to mix CSS and MathML-presentation (at least) see
appendix G in w3c MathML 2.0 spec
<http://www.w3.org/TR/2003/REC-MathML2-20031021/appendixg.html>

I was wondering that CSS is a powerfull yet simple way to customize
rendering (in HTML and in MathML presentation too). Is there a generic
library that can parse any XML file, find style data (maybe we can help
parser to find styles), parse style data, AND apply CSS rules.
 
O

Oliver Wong

oulan bator said:
I don't think CSS is dead, and that XSL stands right for what I need to
do. I know how to handle XSL in java (it is built in since 1.4 IMHO)

I'm not saying CSS is dead; in fact, W3C is actively working on CSS3.
I'm just saying that the W3C also recommends that you do NOT use CSS to
format XML data, and that you DO use XSL to format it (as indicated in the
link I made in another post in this thread).

I went to the javadocs,
http://java.sun.com/j2se/1.5.0/docs/api/index.html, and did a search for
"XSL", and found zero results. Where do you see XSL support built into Java?
I was wondering that CSS is a powerfull yet simple way to customize
rendering (in HTML and in MathML presentation too). Is there a generic
library that can parse any XML file, find style data (maybe we can help
parser to find styles), parse style data, AND apply CSS rules.

Applying CSS rules to a document only makes sense in the context where
you want to DISPLAY the document. In other words, it does not make sense to
apply CSS to the in-memory tree-like representation of an XML document. The
CSS language, for example, allows you to place conditionals on the style
rules depending on whether the document should be displayed on screen, or on
paper, something which cannot possibly known before the time comes to
actually print or display the document.

Once we have a better idea of what you are doing to display your MathML
documents (because I'm pretty sure MathML is not built into Java either), we
might be able to further advise you with regards to CSS, but my initial
claim still stands:

You'll get more support using XSL to manipulate the presentation of XML
documents than you will with CSS.

- Oliver
 
O

oulan bator

Where do you see XSL support built into Java?
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/transform/TransformerFactory.html
Once we have a better idea of what you are doing to display your MathML
documents
I do want to display MathML ! I'm building a java MathML viewer ! Thats
why I need CSS
I've been looking a lot around, and didn't find any java implementation
of a CSS parser that I could apply to my MathML tree

I'm starting to think that it does not exist, I'll have to implement
CSS support by myself, but I can't keep thinking that it is possible to
build a generic CSS support !
 
D

Dag Sunde

oulan bator said:
I do want to display MathML ! I'm building a java MathML viewer ! Thats
why I need CSS
I've been looking a lot around, and didn't find any java implementation
of a CSS parser that I could apply to my MathML tree

You won't find *any* implementation for *any language of a CSS parser that
you could apply to a MathML tree

MathML is an XML markup-language for mathematics, and not a visual renderer
You use xsl(t) to transform it into something that can be visualy rendered,
and possibly apply a css stylesheet to that.
I'm starting to think that it does not exist, I'll have to implement It doesn't
CSS support by myself, but I can't keep thinking that it is possible to
build a generic CSS support !
It just doesn't make sense to use css on a mathML document...
 
C

caroline.atienza

I don't agree with you, Dag !!
MathML-presentation IS a visual renderer with color tricks and font
size style etc....
as well as HTML !
I know how to "apply" by hand CSS rules to a MathML tree ! There is
absolutely no contradiction. I'm looking for a tool that help me to
process this rules by computer !
It just doesn't make sense to use css on a mathML document...
It does to me, sorry
 
D

Dag Sunde

I don't agree with you, Dag !!
MathML-presentation IS a visual renderer with color tricks and font
size style etc....
as well as HTML !
I know how to "apply" by hand CSS rules to a MathML tree ! There is
absolutely no contradiction. I'm looking for a tool that help me to
process this rules by computer !

It does to me, sorry

Can you please post some links or show me how to "apply" those
css-rules to MathML documents by hand?

I'm not trying to be sarcastic here, I'm really interested i
how you do this!

Or maybe I'm just grossly misunderstand what you mean...?
 
O

oulan bator

yep,
and many others, but they don't fit my requirements :
1- must be a reusable component that I can embbed in my apps
2- the component must edit a constrained subset of mathml (for
instance, sometimes I want to allow a=b+c, but not a+b=c+d )
3- it is destinated to our customers

I thought (I'm evaluating) that it would be easier to have my own
editor ... but I might be wrong

(but you're right, I can see that I've said "viewer", Sorry. But the
target remains to have an editor/viewer, and the first step is to have
a viewer
 
O

Oliver Wong

oulan bator said:
Okay, thanks.
I do want to display MathML ! I'm building a java MathML viewer ! Thats
why I need CSS
I've been looking a lot around, and didn't find any java implementation
of a CSS parser that I could apply to my MathML tree

So you're implementing your own viewer from scratch, right? So wouldn't
it be your job to implement applying the styles to your view as well? What
I'm getting at is that it doesn't seem reasonable to try to seperate the
concern of taking an XML document and from that, putting pixels on the
screen with the concern of deciding what set of pixels to put on the screen.
The best you could hope for, I suspect, is a CSS parser; but you still need
to manually interpret the CSS data you've got and apply that to your own
graphical representation of the math formulas.

- Oliver
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top