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 bu...@apache.org on 2004/03/12 06:31:45 UTC
DO NOT REPLY [Bug 27620] New: -
xalan:indent-amount does not work in Translets
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27620>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=27620
xalan:indent-amount does not work in Translets
Summary: xalan:indent-amount does not work in Translets
Product: Xerces2-J
Version: 2.6.0
Platform: All
OS/Version: Other
Status: NEW
Severity: Minor
Priority: Other
Component: Serialization
AssignedTo: xerces-j-dev@xml.apache.org
ReportedBy: alick.buckley@lansa.com.au
I have been using Xalan 2.4.1 for several years and have been planning to
upgrade to 2.5.1, 2.5.2 or 2.6.0
What has delayed the upgrade is that the xalan:indent-amount is no working in
translets for releases after 2.4.1.
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" xalan:indent-
amount="2" />
The xalan:indent-amount does not work when the style sheet has been compiled to
a translet class.
Also the xalan namespaces are not removed, I have to include xalan in the
exclude-result-prefixes attribute along with other namespaces.
I use the xsltc class to compile a style sheet into a translet class
xsltc.compile ( inputStream, className )
Then I deploy the translet
I need to call the setIndentAmount to get indenting to work.
handler.setIndentAmount ( 2 ) ;
The translet is not honouring the xalan:indent-amount attribute on the output.
============================================================================
handler.setIndentAmount commented out
<Orders>
<SalesOrder SONumber="">
<Customer CustNumber="">
<CustName/>
<Street/>
<City/>
<State/>
<PostCode/>
</Customer>
<OrderDate/>
</SalesOrder>
</Orders>
handler.setIndentAmount ( 2 )
<Orders>
<SalesOrder SONumber="">
<Customer CustNumber="">
<CustName/>
<Street/>
<City/>
<State/>
<PostCode/>
</Customer>
<OrderDate/>
</SalesOrder>
</Orders>
xalan removed from exclude-prefix attribute
<Orders xmlns:xalan="http://xml.apache.org/xslt">
<SalesOrder SONumber="">
<Customer CustNumber="">
<CustName/>
<Street/>
<City/>
<State/>
<PostCode/>
</Customer>
<OrderDate/>
</SalesOrder>
</Orders>
============================================================================
import java.io.* ;
import java.util.* ;
import org.w3c.dom.* ;
import org.xml.sax.* ;
import org.xml.sax.helpers.* ;
import javax.xml.parsers.* ;
import javax.xml.transform.* ;
import javax.xml.transform.sax.* ;
import javax.xml.transform.dom.* ;
import javax.xml.transform.stream.* ;
import org.apache.xalan.xsltc.dom.SAXImpl ;
import org.apache.xalan.xsltc.dom.XSLTCDTMManager ;
import org.apache.xml.serializer.SerializationHandler ;
import org.apache.xalan.xsltc.runtime.AbstractTranslet ;
import org.apache.xalan.xsltc.runtime.output.TransletOutputHandlerFactory ;
public final class XMLTest implements ErrorHandler, ErrorListener,
EntityResolver
{
private final static String METHOD = "xml" ;
private final static String ENCODING = "UTF-8" ;
private final static String EMPTY_STRING = "" ;
private final static String SAX_PARSER
= "org.apache.xerces.parsers.SAXParser" ;
private final static String FEATURE_NAMESPACES
= "http://xml.org/sax/features/namespaces" ;
private final static String FEATURE_VALIDATION
= "http://xml.org/sax/features/validation" ;
private final static String FEATURE_VALIDATION_SCHEMA
= "http://apache.org/xml/features/validation/schema" ;
private final static String FEATURE_VALIDATION_DYNAMIC
="http://apache.org/xml/features/validation/dynamic" ;
public final static void main ( String[] args ) throws Exception
{
XMLTest test = new XMLTest () ;
String xmlSource = "<?xml version=\"1.0\" encoding=\"utf-8\"?
><root></root>" ;
String result = test.transformTranslet (
xmlSource, "com.lansa.jsm.translet.SendOrder", false ) ;
System.out.println ( result ) ;
}
public final String transformTranslet ( String xmlSource, String className,
boolean schemaValidation ) throws Exception
{
InputSource inputSource = new InputSource ( new StringReader (
xmlSource ) ) ;
XMLReader reader = createXMLReader ( schemaValidation ) ;
SAXSource saxSource = new SAXSource ( reader, inputSource ) ;
Class transletClass = Class.forName ( className ) ;
AbstractTranslet translet = (AbstractTranslet)transletClass.newInstance
() ;
XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance () ;
SAXImpl document = (SAXImpl)dtmManager.getDTM ( saxSource, false, null,
true, false, translet.hasIdCall () ) ;
String unicodeResult = transformTranslet ( translet, document ) ;
document = null ;
translet = null ;
transletClass = null ;
return unicodeResult ;
}
private final String transformTranslet ( AbstractTranslet translet, SAXImpl
document ) throws Exception
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream (
5000 ) ;
TransletOutputHandlerFactory factory =
TransletOutputHandlerFactory.newInstance () ;
factory.setEncoding ( ENCODING ) ; // translet._encoding
factory.setOutputMethod ( METHOD ) ; // translet._method
factory.setOutputStream ( outputStream ) ;
factory.setOutputType ( TransletOutputHandlerFactory.STREAM ) ;
SerializationHandler handler = factory.getSerializationHandler () ;
handler.setIndentAmount ( 2 ) ;
translet.prepassDocument ( document ) ;
translet.transform ( document, handler ) ;
byte[] byteArray = outputStream.toByteArray () ;
String unicodeResult = new String ( byteArray, "UTF-8" ) ;
handler = null ;
factory = null ;
outputStream = null ;
return unicodeResult ;
}
private final XMLReader createXMLReader ( boolean schemaValidation ) throws
Exception
{
XMLReader reader = XMLReaderFactory.createXMLReader ( SAX_PARSER ) ;
reader.setFeature ( FEATURE_NAMESPACES, true ) ;
reader.setFeature ( FEATURE_VALIDATION, true ) ;
if ( schemaValidation )
{
reader.setFeature ( FEATURE_VALIDATION_SCHEMA, true ) ;
}
reader.setFeature ( FEATURE_VALIDATION_DYNAMIC, true ) ;
reader.setErrorHandler ( this ) ;
reader.setEntityResolver ( this ) ;
return reader ;
}
public final InputSource resolveEntity ( String publicId, String systemId )
{
return null ;
}
public final void warning ( SAXParseException e ) throws SAXParseException
{
throw e ;
}
public final void error ( SAXParseException e ) throws SAXParseException
{
throw e ;
}
public final void fatalError ( SAXParseException e ) throws
SAXParseException
{
throw e ;
}
public final void warning ( TransformerException e ) throws
TransformerException
{
throw e ;
}
public final void error ( TransformerException e ) throws
TransformerException
{
throw e ;
}
public final void fatalError ( TransformerException e ) throws
TransformerException
{
throw e ;
}
}
==============================================================================
XSL used in test, this was compiled and the class used.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" exclude-result-prefixes="rdml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdml="http://www.lansa.com/2000/XML/Function"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" xalan:indent-
amount="2"/>
<xsl:template match="/">
<Orders>
<SalesOrder SONumber="{/rdml:function/rdml:fields/rdml:field
[@name='ORDER']/@value}">
<Customer CustNumber="{/rdml:function/rdml:fields/rdml:field
[@name='CUSTNUM']/@value}">
<CustName><xsl:value-of
select="/rdml:function/rdml:fields/rdml:field[@name='NAME']/@value"/></CustName>
<Street><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
[@name='STREET']/@value"/></Street>
<City><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
[@name='CITY']/@value"/></City>
<State><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
[@name='STATE']/@value"/></State>
<PostCode><xsl:value-of
select="/rdml:function/rdml:fields/rdml:field[@name='ZIP']/@value"/></PostCode>
</Customer>
<OrderDate><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
[@name='ORDDTE']/@value"/></OrderDate>
</SalesOrder>
</Orders>
==============================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org