XML-Stylesheet declaration in DTD causing issues

Discussion in 'XML' started by Sarah Haskins, Jan 13, 2004.

  1. I have a few questions about this problem I'm having involving XML,
    DTD, and XSL.

    I'm working with this DTD which defines a stylesheet, as such...

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    <!ELEMENT ABCMessage (Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7,
    Tag8*)>
    <!ATTLIST ABCMessage
    version CDATA #REQUIRED
    release CDATA #REQUIRED
    >

    etc...

    What does it mean that this DTD has an xml-stylesheet tag in it? Is
    this a valid or meaningful tag for a DTD?

    It's causing me a problem because I'm using Java code and XSL to
    "print" an XML document which complies with this DTD. My Java code
    looks something like this...

    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();

    transformer.setOutputProperty("indent", indent ? "yes" : "no");
    transformer.setOutputProperty("method", methodType);

    // if ommitting xml declaration, omit_xml_declaration will be "yes"
    // otherwise, omit_xml_declaration will not be provided, "no" is the
    default
    if (omitXMLDeclaration)
    {
    transformer.setOutputProperty("omit-xml-declaration", "yes");
    }

    DocumentType docType = doc.getDoctype();
    if (docType != null)
    {
    transformer.setOutputProperty("doctype-system",
    docType.getSystemId());
    }

    DOMSource source = new DOMSource(doc);
    StringWriter resultWriter = new StringWriter();
    StreamResult result = new StreamResult(resultWriter);
    transformer.transform(source, result);
    return resultWriter.getBuffer().toString();

    The Transformer stuff is from the javax.xml.transformer package. What
    I'm seeing in my result is that xml-stylesheet tag. It even appears
    multiple times, like this...

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    <?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    <!DOCTYPE ABCMessage SYSTEM "abc-xml.dtd">
    <ABCMessage release="3" version="2">
    ....
    </ABCMessage>


    What is causing this stylesheet tag to appear at all in my resulting
    XML? Should I try to remove it? I also don't exactly know why its
    appearing more than once, but I suspect it could have to do with the
    fact that I call the code snippet above more than once.

    Any theories or information about xml-stylesheet in DTD would be
    greatly appreciated.
     
    Sarah Haskins, Jan 13, 2004
    #1
    1. Advertising

  2. Sarah Haskins

    Puff Addison Guest

    Sarah Haskins wrote:

    >I have a few questions about this problem I'm having involving XML,
    >DTD, and XSL.
    >
    >I'm working with this DTD which defines a stylesheet, as such...
    >
    ><?xml version="1.0" encoding="UTF-8"?>
    ><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    ><!ELEMENT ABCMessage (Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7,
    >Tag8*)>
    ><!ATTLIST ABCMessage
    > version CDATA #REQUIRED
    > release CDATA #REQUIRED
    >
    >
    >etc...
    >
    >What does it mean that this DTD has an xml-stylesheet tag in it? Is
    >this a valid or meaningful tag for a DTD?
    >
    >It's causing me a problem because I'm using Java code and XSL to
    >"print" an XML document which complies with this DTD. My Java code
    >looks something like this...
    >
    > TransformerFactory tFactory = TransformerFactory.newInstance();
    > Transformer transformer = tFactory.newTransformer();
    >
    > transformer.setOutputProperty("indent", indent ? "yes" : "no");
    > transformer.setOutputProperty("method", methodType);
    >
    > // if ommitting xml declaration, omit_xml_declaration will be "yes"
    > // otherwise, omit_xml_declaration will not be provided, "no" is the
    >default
    > if (omitXMLDeclaration)
    > {
    > transformer.setOutputProperty("omit-xml-declaration", "yes");
    > }
    >
    > DocumentType docType = doc.getDoctype();
    > if (docType != null)
    > {
    > transformer.setOutputProperty("doctype-system",
    >docType.getSystemId());
    > }
    >
    > DOMSource source = new DOMSource(doc);
    > StringWriter resultWriter = new StringWriter();
    > StreamResult result = new StreamResult(resultWriter);
    > transformer.transform(source, result);
    > return resultWriter.getBuffer().toString();
    >
    >The Transformer stuff is from the javax.xml.transformer package. What
    >I'm seeing in my result is that xml-stylesheet tag. It even appears
    >multiple times, like this...
    >
    ><?xml version="1.0" encoding="UTF-8"?>
    ><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    ><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    ><!DOCTYPE ABCMessage SYSTEM "abc-xml.dtd">
    ><ABCMessage release="3" version="2">
    >...
    ></ABCMessage>
    >
    >
    >What is causing this stylesheet tag to appear at all in my resulting
    >XML? Should I try to remove it? I also don't exactly know why its
    >appearing more than once, but I suspect it could have to do with the
    >fact that I call the code snippet above more than once.
    >
    >Any theories or information about xml-stylesheet in DTD would be
    >greatly appreciated.
    >
    >

    Depending in the way your XSLT stylesheet is written in may be caused by
    the transformer not using default template for Processing Instrictions
    that omits them.

    --
    J. D. Addison
     
    Puff Addison, Jan 14, 2004
    #2
    1. Advertising

  3. Puff Addison <> wrote in message news:<bu3ici$gbb$1$>...
    > Sarah Haskins wrote:
    >
    > >I have a few questions about this problem I'm having involving XML,
    > >DTD, and XSL.
    > >
    > >I'm working with this DTD which defines a stylesheet, as such...
    > >
    > ><?xml version="1.0" encoding="UTF-8"?>
    > ><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    > ><!ELEMENT ABCMessage (Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7,
    > >Tag8*)>
    > ><!ATTLIST ABCMessage
    > > version CDATA #REQUIRED
    > > release CDATA #REQUIRED
    > >
    > >
    > >etc...
    > >
    > >What does it mean that this DTD has an xml-stylesheet tag in it? Is
    > >this a valid or meaningful tag for a DTD?
    > >
    > >It's causing me a problem because I'm using Java code and XSL to
    > >"print" an XML document which complies with this DTD. My Java code
    > >looks something like this...
    > >
    > > TransformerFactory tFactory = TransformerFactory.newInstance();
    > > Transformer transformer = tFactory.newTransformer();
    > >
    > > transformer.setOutputProperty("indent", indent ? "yes" : "no");
    > > transformer.setOutputProperty("method", methodType);
    > >
    > > // if ommitting xml declaration, omit_xml_declaration will be "yes"
    > > // otherwise, omit_xml_declaration will not be provided, "no" is the
    > >default
    > > if (omitXMLDeclaration)
    > > {
    > > transformer.setOutputProperty("omit-xml-declaration", "yes");
    > > }
    > >
    > > DocumentType docType = doc.getDoctype();
    > > if (docType != null)
    > > {
    > > transformer.setOutputProperty("doctype-system",
    > >docType.getSystemId());
    > > }
    > >
    > > DOMSource source = new DOMSource(doc);
    > > StringWriter resultWriter = new StringWriter();
    > > StreamResult result = new StreamResult(resultWriter);
    > > transformer.transform(source, result);
    > > return resultWriter.getBuffer().toString();
    > >
    > >The Transformer stuff is from the javax.xml.transformer package. What
    > >I'm seeing in my result is that xml-stylesheet tag. It even appears
    > >multiple times, like this...
    > >
    > ><?xml version="1.0" encoding="UTF-8"?>
    > ><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    > ><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    > ><!DOCTYPE ABCMessage SYSTEM "abc-xml.dtd">
    > ><ABCMessage release="3" version="2">
    > >...
    > ></ABCMessage>
    > >
    > >
    > >What is causing this stylesheet tag to appear at all in my resulting
    > >XML? Should I try to remove it? I also don't exactly know why its
    > >appearing more than once, but I suspect it could have to do with the
    > >fact that I call the code snippet above more than once.
    > >
    > >Any theories or information about xml-stylesheet in DTD would be
    > >greatly appreciated.
    > >
    > >

    > Depending in the way your XSLT stylesheet is written in may be caused by
    > the transformer not using default template for Processing Instrictions
    > that omits them.


    I don't actually use a XSLT file. As you can see in the code snippet
    above, I don't pass a DOMSource when I call
    tFactory.newTransformer();. So I'm basically creating a blank XSL in
    memory, in order to do a full copy of the XML into a Stream. If
    there's a way to omit xml-stylesheet in an XSL doc, then there's got
    to be a way to do this in the Java code too. Any idea which attribute
    that would be? I'm familiar with "omit-xml-declaration", but I don't
    think there's an "omit-xml-stylesheet" option.

    Or even a better way to get a String value from an XML Document. I'm
    open to suggestions.
     
    Sarah Haskins, Jan 14, 2004
    #3
  4. Sarah Haskins

    Puff Addison Guest

    Sarah Haskins wrote:

    >Puff Addison <> wrote in message news:<bu3ici$gbb$1$>...
    >
    >
    >>Sarah Haskins wrote:
    >>
    >>
    >>
    >>>I have a few questions about this problem I'm having involving XML,
    >>>DTD, and XSL.
    >>>
    >>>I'm working with this DTD which defines a stylesheet, as such...
    >>>
    >>><?xml version="1.0" encoding="UTF-8"?>
    >>><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    >>><!ELEMENT ABCMessage (Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7,
    >>>Tag8*)>
    >>><!ATTLIST ABCMessage
    >>> version CDATA #REQUIRED
    >>> release CDATA #REQUIRED
    >>>
    >>>
    >>>etc...
    >>>
    >>>What does it mean that this DTD has an xml-stylesheet tag in it? Is
    >>>this a valid or meaningful tag for a DTD?
    >>>
    >>>It's causing me a problem because I'm using Java code and XSL to
    >>>"print" an XML document which complies with this DTD. My Java code
    >>>looks something like this...
    >>>
    >>> TransformerFactory tFactory = TransformerFactory.newInstance();
    >>> Transformer transformer = tFactory.newTransformer();
    >>>
    >>> transformer.setOutputProperty("indent", indent ? "yes" : "no");
    >>> transformer.setOutputProperty("method", methodType);
    >>>
    >>> // if ommitting xml declaration, omit_xml_declaration will be "yes"
    >>> // otherwise, omit_xml_declaration will not be provided, "no" is the
    >>>default
    >>> if (omitXMLDeclaration)
    >>> {
    >>> transformer.setOutputProperty("omit-xml-declaration", "yes");
    >>> }
    >>>
    >>> DocumentType docType = doc.getDoctype();
    >>> if (docType != null)
    >>> {
    >>> transformer.setOutputProperty("doctype-system",
    >>>docType.getSystemId());
    >>> }
    >>>
    >>> DOMSource source = new DOMSource(doc);
    >>> StringWriter resultWriter = new StringWriter();
    >>> StreamResult result = new StreamResult(resultWriter);
    >>> transformer.transform(source, result);
    >>> return resultWriter.getBuffer().toString();
    >>>
    >>>The Transformer stuff is from the javax.xml.transformer package. What
    >>>I'm seeing in my result is that xml-stylesheet tag. It even appears
    >>>multiple times, like this...
    >>>
    >>><?xml version="1.0" encoding="UTF-8"?>
    >>><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    >>><?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?>
    >>><!DOCTYPE ABCMessage SYSTEM "abc-xml.dtd">
    >>><ABCMessage release="3" version="2">
    >>>...
    >>></ABCMessage>
    >>>
    >>>
    >>>What is causing this stylesheet tag to appear at all in my resulting
    >>>XML? Should I try to remove it? I also don't exactly know why its
    >>>appearing more than once, but I suspect it could have to do with the
    >>>fact that I call the code snippet above more than once.
    >>>
    >>>Any theories or information about xml-stylesheet in DTD would be
    >>>greatly appreciated.
    >>>
    >>>
    >>>
    >>>

    >>Depending in the way your XSLT stylesheet is written in may be caused by
    >>the transformer not using default template for Processing Instrictions
    >>that omits them.
    >>
    >>

    >
    >I don't actually use a XSLT file. As you can see in the code snippet
    >above, I don't pass a DOMSource when I call
    >tFactory.newTransformer();. So I'm basically creating a blank XSL in
    >memory, in order to do a full copy of the XML into a Stream. If
    >there's a way to omit xml-stylesheet in an XSL doc, then there's got
    >to be a way to do this in the Java code too. Any idea which attribute
    >that would be? I'm familiar with "omit-xml-declaration", but I don't
    >think there's an "omit-xml-stylesheet" option.
    >
    >Or even a better way to get a String value from an XML Document. I'm
    >open to suggestions.
    >
    >

    Oops! I did not read the code very carefully. As the Transformer does a
    simple copy the question is why does the stylesheet processing
    instuction occur twice? If you want to get rid of the style sheet
    processing instruction you will need to use a simple stylesheet to do
    the transformation.

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

    Should remove the processing instrunctions and copy the markup.
    Puff

    --
    J. D. Addison
    email
     
    Puff Addison, Jan 15, 2004
    #4
    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. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    615
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  2. Steven An
    Replies:
    1
    Views:
    541
    Martin Honnen
    Nov 23, 2004
  3. David Blickstein
    Replies:
    3
    Views:
    1,089
    David Blickstein
    Aug 2, 2005
  4. David Blickstein
    Replies:
    14
    Views:
    6,448
    Harrie
    Oct 16, 2005
  5. test
    Replies:
    2
    Views:
    2,192
    Oliver Wong
    Jul 28, 2006
Loading...

Share This Page