[jdom-interest] XSL transformations and missing doctypes

Lee Turner lee at leeturner.org
Wed Aug 25 03:59:22 PDT 2004


Hi

Now I understand.  My cause for confusion previously was due to the fact
that when I used the javax.xml classes to perform the transform, I used a
StreamResult to output the result to System.out and the doctype was included
in this.  I have just tried the same code with the SAXResult and DOMResult
and as you say, the doctype info is not generated.

Thank you very much for talking me through this and for supplying the code
to allow me to get the doctype in there after the transform.

Many thanks
Lee

----- Original Message ----- 
From: "Per Norrman" <per.norrman at austers.se>
To: "Lee Turner" <lee at leeturner.org>
Cc: <jdom-interest at jdom.org>
Sent: Wednesday, August 25, 2004 10:18 AM
Subject: Re: [jdom-interest] XSL transformations and missing doctypes


> Hi again,
>
> I was unclear! As you say, "Once the result tree has been generated by the
xslt
> processor, xsl:output controls the serialisation of this to an output
document".
> But only if it is the XSLT processor that is doing the serialization
itself.
>
> JDOMResult extends SAXResult, in which case no doctype stuff is generated.
>
> However, you can use the getOuputProperties() method of the Templates
class
> and automate the generation of a doctype--dependant on the xsl:output
element
> settings: somethinh like this:
>
>      private static void generateDocType(Templates templates, Document
doc) {
>          Properties prop = templates.getOutputProperties();
>          String systemId = prop.getProperty(OutputKeys.DOCTYPE_SYSTEM);
>          String publicId = prop.getProperty(OutputKeys.DOCTYPE_PUBLIC);
>
>          String name = doc.getRootElement().getName();
>          DocType dt = null;
>          if (systemId != null) {
>              if (publicId != null) {
>                  dt = new DocType(name, publicId, systemId);
>              } else {
>                  dt = new DocType(name, systemId);
>              }
>          }
>          if (dt != null) {
>              doc.setDocType(dt);
>          }
>      }
>
> and then
>
>          JDOMResult result = new JDOMResult();
>          templates.newTransformer().transform(xml, result);
>          Document doc = result.getDocument();
>          generateDocType(templates, doc);
>
> /pmn
>
>
>
> Lee Turner wrote:
>
> > Hi
> >
> > Yes I am specifying the doctype in the xsl:output, but I didn't think
that
> > xsl:output was only applicable when the output document was to be xml.
Once
> > the result tree has been generated by the xslt processor, xsl:output
> > controls the serialisation of this to an output document.  If what you
say
> > is true then I can never generate a valid html 4.01 output document
> > specifying the relevant doctypes without some processing after the
transform
> > has been done.  Is this correct ?  I have read out rules applicable for
both
> > xml and html output controlled by the xsl:output element.
> >
> > Either way, I am still outputting xml as the output format as I want
well
> > formed xml (xhtml) so I should still be able to see the doctype
information
> > in the output.  Like I said in my first email, this does work when I
remove
> > JDOM from the equation which is why I sent a mail to this list (I hope
> > people didn't think that it was way off topic) instead of an xsl list.
If
> > there is nothing I can do about it then I guess I will have to do what
you
> > say and implement some processing after the transformation to insert the
> > correct doctypes but this seems like a hack when afaik I should be able
to
> > do it using pure xsl.
> >
> > I really appreciate you taking the time to respond to my email.
> > Many thanks
> > Lee
> >
> > ----- Original Message ----- 
> > From: "Per Norrman" <per.norrman at austers.se>
> > To: "Lee Turner" <lee at leeturner.org>
> > Cc: <jdom-interest at jdom.org>
> > Sent: Wednesday, August 25, 2004 8:19 AM
> > Subject: Re: [jdom-interest] XSL transformations and missing doctypes
> >
> >
> >
> >>Hi,
> >>
> >>Are you specifying the doctype using the xsl:ouput element? In that
> >>case, note that the xsl:output element is only applicable when
> >>the XSLT processor is generating XML from the result tree.
> >>
> >>Since you are transforming into xhtml, you can easily set
> >>the doctype after the transformation is completed.
> >>
> >>/pmn
> >>
> >>Lee Turner wrote:
> >>
> >>
> >>>Hi
> >>>
> >>>I am using JDOM b10 in my system where I am using xsl to transform my
> >
> > JDOM
> >
> >>>documents into xhtml to be displayed on the front end.  My problem is
> >
> > that
> >
> >>>when the transformation has been done I am missing the doctype that I
> >
> > set in
> >
> >>>the xsl.  The code I am using is as follows :
> >>>
> >>>        //snip
> >>>        Transformer transformer = template.newTransformer();
> >>>        JDOMSource source = new JDOMSource(incomingDocument);
> >>>        JDOMResult result = new JDOMResult();
> >>>        transformer.transform(source, result);
> >>>        return result.getDocument();
> >>>
> >>>I have taken my xsl and tried that outside of JDOM, using static xml
> >
> > instead
> >
> >>>and the doctype is there in the output and I have even just used the
> >>>javax.xml classes to do the transform DOMSource and StreamResult etc
> >>>and the doctype is in the output here as well.
> >>>
> >>>I have looked on the web and news groups and there seem to be a few
> >>>references to missing doctypes, but I couldn't find anything to say
> >
> > whether
> >
> >>>it has been fixed in the latest CVS of JDOM.  I downloaded the daily
> >>>snapshot from the JDOM web site and still saw the same behaviour.
> >>>
> >>>Has anyone else seen this when performing transformations using JDOM  ?
> >>>Any help would be greatly appreciated.
> >>>
> >>>Kind regards
> >>>Lee
> >>>
> >>>_______________________________________________
> >>>To control your jdom-interest membership:
> >>>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> >>>
> >>
> >>
> >
> >
>
>



More information about the jdom-interest mailing list