Maybe I'm not putting all the pieces together correctly, but it sounds like
Xalan 2.2 isn't implementing the getOutputProperties method according to the
TRaX API documentation then.

According to the Javadoc on Sun's site
<http://java.sun.com/j2se/1.4/docs/api/javax/xml/transform/Transformer.html#
getOutputProperties()>, the method documentation states -
"The properties returned should contain properties set by the user, and
properties set by the stylesheet, and these properties are "defaulted" by
default properties specified by section 16 of the XSL Transformations (XSLT)
W3C Recommendation."

Which basically says the defaults should be set according to section 16 of
the XSLT spec <http://www.w3.org/TR/xslt#output>. I read section 16 and it
explicit states -
"The default for the method attribute is chosen as follows. If
 * the root node of the result tree has an element child,

 * the expanded-name of the first element child of the root node (i.e. the
document element) of the result tree  has local part html (in any
combination of upper and lower case) and a null namespace URI, and

 * any text nodes preceding the first element child of the root node of the
result tree contain only whitespace characters,

 then the default output method is html; otherwise, the default output
method is xml. The default output method should be used if there are no
xsl:output elements or if none of the xsl:output elements specifies a value
for the method attribute."

My interpretation of these two documents is that I should be getting back a
default value of "html" for "method" if my stylesheet follows the section 16
rules. The XSL file I included in my original email follows these rules,
correct?

Am I reading these documents incorrectly?

-Nathan

-----Original Message-----
From: Gary L Peskin [mailto:[EMAIL PROTECTED]
Sent: Monday, July 22, 2002 4:05 PM
To: 'Xalan-J-User (E-mail)'
Subject: RE: Default Output Method in Xalan 2.2


Nathan --

You are asking for the OutputProperties present in the Transformer.
Your Transformer is built directly from your XSL file.  These
OutputProperties are built into the transformer at XSLT "compile time"
from your stylesheet and that's what they reflect.

The examination for the proper properties to use at run time is made at
the time that XalanJ is writing out to your theResult.  The switch to
the HTML properties at run time has no effect on the OutputProperties
compiled into your Transformer which is why you're seeing the results
that you're seeing.

What you might try is casting transformer to a TransformerImpl.  Then,
do a getSerializer().  Then do a getOutputFormat(), like this:

  TransformerImpl ti = (TransformerImpl) transformer;
  props = ti.getSerializer().getOutputFormat();

See if those props are what you're looking for.  Bear in mind that this
is a XalanJ-specific solution and is subject to change.  Also, it is not
always reliable but in your case, if it works, it should work all the
time for what you need.  If this doesn't work, there is another, more
complicated way, but I think this will work for you.

The safest XSLT way to do this, I think, would be for you to examine the
StreamResult yourself (you might write it to a byte array or
StringBuffer) and determine if the first element is html and is preceded
only by text whitespace nodes.

HTH,
Gary

> -----Original Message-----
> From: Beyer,Nathan [mailto:[EMAIL PROTECTED] 
> Sent: Monday, July 22, 2002 1:23 PM
> To: 'Xalan-J-User (E-mail)'
> Subject: RE: Default Output Method in Xalan 2.2
> 
> 
> 
> Here's a quick snippet of what I'm doing currently to setup 
> the transformer and dump out the properties:
> 
> //......
> 
> StreamSource theXsl = new StreamSource(file);
> StringReader sReader = new StringReader(outBuffer.toString());
> StreamSource theXml = new StreamSource(sReader);
> StreamResult theResult = new StreamResult(out);
> 
> TransformerFactory tFactory = 
> TransformerFactory.newInstance(); Transformer transformer = 
> tFactory.newTransformer(theXsl);
> 
> java.util.Properties props = transformer.getOutputProperties();
> props.list(System.out); //just dumping the properties right 
> now for debugging purposes
> 
> transformer.transform(theXml, theResult);
> 
> props = transformer.getOutputProperties();
> props.list(System.out);
> 
> //.....
> 
> 
> What I'd like to do is have some conditional processing to 
> see what the output method and/or media-type is going to be, 
> so I can determine what to set the Content-type of HTTP header to.
> 
> Also, you'll notice I retrieve the properties before and 
> after the transform and they don't change. If I place an 
> output element with a different method it will be reflected 
> in the properties, so the property switch seems to be 
> happening BEFORE the actual transform. So, as long as the XSL 
> file contains the output element, I'm fine, but if it doesn't 
> I can't tell what to do. What makes this worse is that the 
> "default" properties look the same as if some set <xsl:output 
> method="xml"/>.
> 
> -Nathan Beyer
> 
> -----Original Message-----
> From: Gary L Peskin [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 22, 2002 1:21 PM
> To: 'Xalan-J-User (E-mail)'
> Subject: RE: Default Output Method in Xalan 2.2
> 
> 
> Nathan --
> 
> You haven't shown where you're getting the OutputProperties 
> from or exactly what sort of conditional processing you're 
> trying to do.  Since there is no xsl:output element, the 
> properties switch has to occur at run time once the output 
> can be examined after the transform is completed.
> 
> We'll need a fuller description of what you're trying to do 
> before we can intelligently address you're question.  XalanJ 
> 2.2 should be working fine in this regard, I believe.
> 
> Gary
> 
> > -----Original Message-----
> > From: Beyer,Nathan [mailto:[EMAIL PROTECTED]
> > Sent: Monday, July 22, 2002 9:47 AM
> > To: Xalan-J-User (E-mail)
> > Subject: Default Output Method in Xalan 2.2
> > 
> > 
> > 
> > I'm using Xalan 2.2 do some transforming and I'd like to use
> > the Output Properties to do some conditional processing, but 
> > have noticed that the default properties don't map up to the 
> > XSLT specification.
> > 
> > According to the specification, if the following is true,
> > then the default "method" should be "html".
> > *   the root node of the result tree has an element child,
> > *   the expanded-name of the first element child of the 
> > root node (i.e.
> > the document element) of the result tree has local part html 
> > (in any combination of upper and lower case) and a null 
> > namespace URI, and
> > *   any text nodes preceding the first element child of the 
> > root node of
> > the result tree contain only whitespace characters,
> > I'm not finding this to be the case in Xalan 2.2. It seems to 
> > always default to "xml".
> > 
> > Here's the XSL I'm using to construct my transformer with:
> > 
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> >     <xsl:template match="/">
> >             <html>
> >                     <body>
> >                             Writing some information.
> >                     </body>
> >             </html>
> >     </xsl:template>
> > </xsl:stylesheet>
> > 
> > Here's a list of all the properties and there values (these
> > are the defaults, since I'm not setting anything):
> > -- listing properties --
> > method=xml
> > encoding=UTF-8
> > omit-xml-declaration=no {http://xml.apache.org/xslt}indent-amount=0
> > indent=no
> > standalone=no 
> > {http://xml.apache.org/xslt}content-handler=org.apache.xalan.s
> erialize.Seria
> lizer... 
> {http://xml.apache.org/xslt}entities=org/apache/xalan/serializ
e/XMLEntit
ie..
.
version=1.0
media-type=text/xml


The odd part is that according to these properties, it should be
outputting an XML document with an XML declaration, but the output is
coming out as though the default "method" is "html".


Does anyone know if this is a known issue or if it's fixed in a later
version?

Thanks.
---
Nathan Beyer

CONFIDENTIALITY NOTICE

This message and any included attachments are
from Cerner Corporation and are intended only
for the addressee. The information contained
in this message is confidential and may
constitute inside or non-public information
under international, federal, or state securities
laws. Unauthorized forwarding, printing, copying,
distribution, or use of such information is
strictly prohibited and may be unlawful. If
you are not the addressee, please promptly
delete this message and notify the sender of
the delivery error by e-mail or you may call
Cerner's corporate offices in Kansas City,
Missouri, U.S.A at (+1) (816)221-1024.
----------------------------------------- -

Reply via email to