Castor Mapping with XSLT

Discussion in 'Java' started by wlaver@gmail.com, Aug 21, 2006.

  1. Guest

    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
    , Aug 21, 2006
    #1
    1. Advertising

  2. Daniel Dyer Guest

    On Mon, 21 Aug 2006 21:37:07 +0100, <> wrote:

    > 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).

    --
    Daniel Dyer
    http://www.dandyer.co.uk
    Daniel Dyer, Aug 21, 2006
    #2
    1. Advertising

  3. mbuckley Guest

    Thanks Dan, that worked for me.

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

    Cheers,

    Mike

    Daniel Dyer wrote:
    > On Mon, 21 Aug 2006 21:37:07 +0100, <> wrote:
    >
    > > 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).
    >
    > --
    > Daniel Dyer
    > http://www.dandyer.co.uk
    mbuckley, Aug 21, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D L.Strang
    Replies:
    0
    Views:
    545
    D L.Strang
    Jul 9, 2003
  2. Ajay Singh Tomar

    Castor File Mapping ???

    Ajay Singh Tomar, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    424
    Ajay Singh Tomar
    Jan 19, 2004
  3. Chris
    Replies:
    0
    Views:
    382
    Chris
    Feb 26, 2004
  4. Sam Hwang
    Replies:
    0
    Views:
    607
    Sam Hwang
    Apr 26, 2005
  5. Chris
    Replies:
    0
    Views:
    437
    Chris
    Feb 26, 2004
Loading...

Share This Page