Castor Mapping with XSLT

W

wlaver

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
 
D

Daniel Dyer

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?

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/exola...tml#addProcessingInstruction(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).
 
M

mbuckley

Thanks Dan, that worked for me.

I will take a look at JiBX, as I have similar complaints about castors
mapping files.

Cheers,

Mike
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top