You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Benson Margulies <bi...@gmail.com> on 2009/10/30 15:59:27 UTC

doctype?

I'm not sure if I should be consulting Xerces, Xalan, or a beer.

I've got a DOM tree with a doctype on it.

I want to serialize it.

I use the usual TraX call. No doctype lands in the output. I'm very
carefully using Xerces for the DOM and Xalan for TraX.

Am I just in the land of RTfM?

Re: doctype?

Posted by Benson Margulies <bi...@gmail.com>.
Thanks. LSSerializer did the job. I don't like doctypes, but I'm stuck with
some.

On Fri, Oct 30, 2009 at 12:45 PM, Michael Glavassevich
<mr...@ca.ibm.com>wrote:

> Benson,
>
> I expect the response that you would get from the Xalan folks is that the
> DOCTYPE isn't part of the data model [1][2] so doesn't appear in the result
> of the transform. I understand that the identity transformer is supposed to
> behave like following stylesheet snippet:
>
> <xsl:template match="@*|node()">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()"/>
>   </xsl:copy>
> </xsl:template>
>
> and that only includes nodes in the XPath data model. I think some folks
> believe the JAXP equivalent should copy everything, not just what's
> representable in the data model, but apparently Xalan and perhaps other XSLT
> processors do not do that.
>
> You could try another API like the LSSerializer [3] which will serialize
> the full content of the DOM.
>
> Thanks.
>
> [1] http://www.w3.org/TR/1999/REC-xslt-19991116#data-model
> [2] http://www.w3.org/TR/xpath#data-model
> [3]
> http://xerces.apache.org/xerces2-j/javadocs/api/org/w3c/dom/ls/LSSerializer.html
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Benson Margulies <bi...@gmail.com> wrote on 10/30/2009 10:59:27 AM:
>
>
> > I'm not sure if I should be consulting Xerces, Xalan, or a beer.
> >
> > I've got a DOM tree with a doctype on it.
> >
> > I want to serialize it.
> >
> > I use the usual TraX call. No doctype lands in the output. I'm very
> > carefully using Xerces for the DOM and Xalan for TraX.
> >
> > Am I just in the land of RTfM?
>

Re: doctype?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Michael Ludwig <mi...@gmx.de> wrote on 11/24/2009 12:20:15 PM:

> Michael Glavassevich schrieb am 24.11.2009 um 12:02:29 (-0500):
> >
> > A DOCTYPE can be specified programmatically [1][2][3], so you don't
> > need to write a stylesheet.
>
> True, thanks. But I assumed the OP had already written one, as he wrote:
>
> > > > > I use the usual TraX call. No doctype lands in the output. I'm
> > > > > very carefully using Xerces for the DOM and Xalan for TraX.
>
> I might be wrong, but the first of the three references you gave is
> probably not related to specifying the DOCTYPE.

Good catch. I meant to post a link to setOutputProperty():

http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/transform/Transformer.html#setOutputProperty
(java.lang.String,%20java.lang.String)

> > [1] http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/
> transform/Transformer.html#setParameter
(java.lang.String,%20java.lang.Object)
>
> Best,
>
> --
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: doctype?

Posted by Michael Ludwig <mi...@gmx.de>.
Michael Glavassevich schrieb am 24.11.2009 um 12:02:29 (-0500):
> 
> A DOCTYPE can be specified programmatically [1][2][3], so you don't
> need to write a stylesheet.

True, thanks. But I assumed the OP had already written one, as he wrote:

> > > > I use the usual TraX call. No doctype lands in the output. I'm
> > > > very carefully using Xerces for the DOM and Xalan for TraX.

I might be wrong, but the first of the three references you gave is
probably not related to specifying the DOCTYPE.

> [1] http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/transform/Transformer.html#setParameter(java.lang.String,%20java.lang.Object)

Best,

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: doctype?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
A DOCTYPE can be specified programmatically [1][2][3], so you don't need to
write a stylesheet. Note that either approach only works if the
DocumentType node has no internal subset. If it has one it will still be
lost if you do this.

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/transform/Transformer.html#setParameter
(java.lang.String,%20java.lang.Object)
[2]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/transform/OutputKeys.html#DOCTYPE_PUBLIC
[3]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/transform/OutputKeys.html#DOCTYPE_SYSTEM

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Michael Ludwig <mi...@gmx.de> wrote on 11/24/2009 08:22:31 AM:

> Michael Glavassevich schrieb am 30.10.2009 um 12:45:44 (-0400):
>
> > Benson Margulies <bi...@gmail.com> wrote on 10/30/2009 10:59:27
> > AM:
> >
> > > I'm not sure if I should be consulting Xerces, Xalan, or a beer.
> > >
> > > I've got a DOM tree with a doctype on it.
> > >
> > > I want to serialize it.
> > >
> > > I use the usual TraX call. No doctype lands in the output. I'm very
> > > carefully using Xerces for the DOM and Xalan for TraX.
>
> You can set a DOCTYPE from XSLT using xsl:output/@doctype-system and
> xsl:output/@doctype-public:
>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:output doctype-public="eins zwei drei"
>     doctype-system="http://eins.de/zwei/drei"/>
>
>   <xsl:template match="@*|node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|node()"/>
>     </xsl:copy>
>   </xsl:template>
> </xsl:stylesheet>
>
> --
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Re: doctype?

Posted by Michael Ludwig <mi...@gmx.de>.
Michael Glavassevich schrieb am 30.10.2009 um 12:45:44 (-0400):

> Benson Margulies <bi...@gmail.com> wrote on 10/30/2009 10:59:27
> AM:
> 
> > I'm not sure if I should be consulting Xerces, Xalan, or a beer.
> >
> > I've got a DOM tree with a doctype on it.
> >
> > I want to serialize it.
> >
> > I use the usual TraX call. No doctype lands in the output. I'm very
> > carefully using Xerces for the DOM and Xalan for TraX.

You can set a DOCTYPE from XSLT using xsl:output/@doctype-system and
xsl:output/@doctype-public:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output doctype-public="eins zwei drei"
    doctype-system="http://eins.de/zwei/drei"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: doctype?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Benson,

I expect the response that you would get from the Xalan folks is that the
DOCTYPE isn't part of the data model [1][2] so doesn't appear in the result
of the transform. I understand that the identity transformer is supposed to
behave like following stylesheet snippet:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

and that only includes nodes in the XPath data model. I think some folks
believe the JAXP equivalent should copy everything, not just what's
representable in the data model, but apparently Xalan and perhaps other
XSLT processors do not do that.

You could try another API like the LSSerializer [3] which will serialize
the full content of the DOM.

Thanks.

[1] http://www.w3.org/TR/1999/REC-xslt-19991116#data-model
[2] http://www.w3.org/TR/xpath#data-model
[3]
http://xerces.apache.org/xerces2-j/javadocs/api/org/w3c/dom/ls/LSSerializer.html

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Benson Margulies <bi...@gmail.com> wrote on 10/30/2009 10:59:27 AM:

> I'm not sure if I should be consulting Xerces, Xalan, or a beer.
>
> I've got a DOM tree with a doctype on it.
>
> I want to serialize it.
>
> I use the usual TraX call. No doctype lands in the output. I'm very
> carefully using Xerces for the DOM and Xalan for TraX.
>
> Am I just in the land of RTfM?

Re: doctype?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Benson,

I expect the response that you would get from the Xalan folks is that the
DOCTYPE isn't part of the data model [1][2] so doesn't appear in the result
of the transform. I understand that the identity transformer is supposed to
behave like following stylesheet snippet:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

and that only includes nodes in the XPath data model. I think some folks
believe the JAXP equivalent should copy everything, not just what's
representable in the data model, but apparently Xalan and perhaps other
XSLT processors do not do that.

You could try another API like the LSSerializer [3] which will serialize
the full content of the DOM.

Thanks.

[1] http://www.w3.org/TR/1999/REC-xslt-19991116#data-model
[2] http://www.w3.org/TR/xpath#data-model
[3]
http://xerces.apache.org/xerces2-j/javadocs/api/org/w3c/dom/ls/LSSerializer.html

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Benson Margulies <bi...@gmail.com> wrote on 10/30/2009 10:59:27 AM:

> I'm not sure if I should be consulting Xerces, Xalan, or a beer.
>
> I've got a DOM tree with a doctype on it.
>
> I want to serialize it.
>
> I use the usual TraX call. No doctype lands in the output. I'm very
> carefully using Xerces for the DOM and Xalan for TraX.
>
> Am I just in the land of RTfM?