Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Castor Mapping with XSLT

Thread view: 
wlaver@gmail.com - 21 Aug 2006 21:37 GMT
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
Daniel Dyer - 21 Aug 2006 21:46 GMT
> 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).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.