I am marshalling a java object to xml. I would like to include a
stylesheet declaration in my castor mapping xml file.
My mapping file looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="main-summary.xsl"?>
<mapping>
content ...
</mapping>
When I marshal the java object, the xml file is created, but the
<?xml-stylesheet line is dropped and no error is reported.
Does anyone know why this happens, or another way that I can output the
xml file with a stylesheet declared?
Thanks,
Mike
> I am marshalling a java object to xml. I would like to include a
> stylesheet declaration in my castor mapping xml file.
[quoted text clipped - 11 lines]
> Does anyone know why this happens, or another way that I can output the
> xml file with a stylesheet declared?
It's because your stylesheet line applies to the mapping file, not the
file output by Castor. Take a look at the addProcessingInstruction of the
Marshaller class
(http://www.castor.org/api/org/exolab/castor/xml/Marshaller.html#addProcessingIns
truction(java.lang.String,
java.lang.String))
You need to do something like this:
marshaller.addProcessingInstruction("xml-stylesheet",
"href=\"main-summary.xsl\" type=\"text/xsl\"");
Dan.
P.S. After trying JiBX (http://www.jibx.org), I doubt I will use Castor
XML again. The mapping files are more elegant, my XML processing was 9
times faster and I had more control over the mapped classes (didn't have
to expose public setters and have non-final fields).

Signature
Daniel Dyer
http://www.dandyer.co.uk
mbuckley - 21 Aug 2006 22:12 GMT
Thanks Dan, that worked for me.
I will take a look at JiBX, as I have similar complaints about castors
mapping files.
Cheers,
Mike
> > I am marshalling a java object to xml. I would like to include a
> > stylesheet declaration in my castor mapping xml file.
[quoted text clipped - 29 lines]
> times faster and I had more control over the mapped classes (didn't have
> to expose public setters and have non-final fields).