XML-Stylesheet declaration in DTD causing issues

S

Sarah Haskins

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 #REQUIREDetc...

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

Puff Addison

Sarah said:
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.
 
S

Sarah Haskins

Puff Addison said:
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.
 
P

Puff Addison

Sarah said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top