XML-Stylesheet declaration in DTD causing issues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sarah Haskins

    #1

    XML-Stylesheet declaration in DTD causing issues

    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[color=blue]
    >[/color]
    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...

    TransformerFact ory tFactory = TransformerFact ory.newInstance ();
    Transformer transformer = tFactory.newTra nsformer();

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

    // if ommitting xml declaration, omit_xml_declar ation will be "yes"
    // otherwise, omit_xml_declar ation will not be provided, "no" is the
    default
    if (omitXMLDeclara tion)
    {
    transformer.set OutputProperty( "omit-xml-declaration", "yes");
    }

    DocumentType docType = doc.getDoctype( );
    if (docType != null)
    {
    transformer.set OutputProperty( "doctype-system",
    docType.getSyst emId());
    }

    DOMSource source = new DOMSource(doc);
    StringWriter resultWriter = new StringWriter();
    StreamResult result = new StreamResult(re sultWriter);
    transformer.tra nsform(source, result);
    return resultWriter.ge tBuffer().toStr ing();

    The Transformer stuff is from the javax.xml.trans former 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.
  • Puff Addison

    #2
    Re: XML-Stylesheet declaration in DTD causing issues

    Sarah Haskins wrote:
    [color=blue]
    >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...
    >
    > TransformerFact ory tFactory = TransformerFact ory.newInstance ();
    > Transformer transformer = tFactory.newTra nsformer();
    >
    > transformer.set OutputProperty( "indent", indent ? "yes" : "no");
    > transformer.set OutputProperty( "method", methodType);
    >
    > // if ommitting xml declaration, omit_xml_declar ation will be "yes"
    > // otherwise, omit_xml_declar ation will not be provided, "no" is the
    >default
    > if (omitXMLDeclara tion)
    > {
    > transformer.set OutputProperty( "omit-xml-declaration", "yes");
    > }
    >
    > DocumentType docType = doc.getDoctype( );
    > if (docType != null)
    > {
    > transformer.set OutputProperty( "doctype-system",
    >docType.getSys temId());
    > }
    >
    > DOMSource source = new DOMSource(doc);
    > StringWriter resultWriter = new StringWriter();
    > StreamResult result = new StreamResult(re sultWriter);
    > transformer.tra nsform(source, result);
    > return resultWriter.ge tBuffer().toStr ing();
    >
    >The Transformer stuff is from the javax.xml.trans former 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.
    >
    >[/color]
    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

    Comment

    • Sarah Haskins

      #3
      Re: XML-Stylesheet declaration in DTD causing issues

      Puff Addison <puff@theaddiso ns.demon.co.uk> wrote in message news:<bu3ici$gb b$1$8300dec7@ne ws.demon.co.uk> ...[color=blue]
      > Sarah Haskins wrote:
      >[color=green]
      > >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...
      > >
      > > TransformerFact ory tFactory = TransformerFact ory.newInstance ();
      > > Transformer transformer = tFactory.newTra nsformer();
      > >
      > > transformer.set OutputProperty( "indent", indent ? "yes" : "no");
      > > transformer.set OutputProperty( "method", methodType);
      > >
      > > // if ommitting xml declaration, omit_xml_declar ation will be "yes"
      > > // otherwise, omit_xml_declar ation will not be provided, "no" is the
      > >default
      > > if (omitXMLDeclara tion)
      > > {
      > > transformer.set OutputProperty( "omit-xml-declaration", "yes");
      > > }
      > >
      > > DocumentType docType = doc.getDoctype( );
      > > if (docType != null)
      > > {
      > > transformer.set OutputProperty( "doctype-system",
      > >docType.getSys temId());
      > > }
      > >
      > > DOMSource source = new DOMSource(doc);
      > > StringWriter resultWriter = new StringWriter();
      > > StreamResult result = new StreamResult(re sultWriter);
      > > transformer.tra nsform(source, result);
      > > return resultWriter.ge tBuffer().toStr ing();
      > >
      > >The Transformer stuff is from the javax.xml.trans former 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.
      > >
      > >[/color]
      > 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.[/color]

      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.newTra nsformer();. 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.

      Comment

      • Puff Addison

        #4
        Re: XML-Stylesheet declaration in DTD causing issues

        Sarah Haskins wrote:
        [color=blue]
        >Puff Addison <puff@theaddiso ns.demon.co.uk> wrote in message news:<bu3ici$gb b$1$8300dec7@ne ws.demon.co.uk> ...
        >
        >[color=green]
        >>Sarah Haskins wrote:
        >>
        >>
        >>[color=darkred]
        >>>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...
        >>>
        >>> TransformerFact ory tFactory = TransformerFact ory.newInstance ();
        >>> Transformer transformer = tFactory.newTra nsformer();
        >>>
        >>> transformer.set OutputProperty( "indent", indent ? "yes" : "no");
        >>> transformer.set OutputProperty( "method", methodType);
        >>>
        >>> // if ommitting xml declaration, omit_xml_declar ation will be "yes"
        >>> // otherwise, omit_xml_declar ation will not be provided, "no" is the
        >>>default
        >>> if (omitXMLDeclara tion)
        >>> {
        >>> transformer.set OutputProperty( "omit-xml-declaration", "yes");
        >>> }
        >>>
        >>> DocumentType docType = doc.getDoctype( );
        >>> if (docType != null)
        >>> {
        >>> transformer.set OutputProperty( "doctype-system",
        >>>docType.getS ystemId());
        >>> }
        >>>
        >>> DOMSource source = new DOMSource(doc);
        >>> StringWriter resultWriter = new StringWriter();
        >>> StreamResult result = new StreamResult(re sultWriter);
        >>> transformer.tra nsform(source, result);
        >>> return resultWriter.ge tBuffer().toStr ing();
        >>>
        >>>The Transformer stuff is from the javax.xml.trans former 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">
        >>><ABCMessag e 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.
        >>>
        >>>
        >>>
        >>>[/color]
        >>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.
        >>
        >>[/color]
        >
        >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.newTr ansformer();. 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.
        >
        >[/color]
        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:styleshe et 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@theaddison s.demon.co.uk

        Comment

        Working...