[ http://issues.apache.org/jira/browse/XALANJ-1821?page=all ]
Brian Minchau updated XALANJ-1821:
----------------------------------
Version: 2.5
(was: Latest Development Code)
> xalan:indent-amount does not work in Translets
> ----------------------------------------------
>
> Key: XALANJ-1821
> URL: http://issues.apache.org/jira/browse/XALANJ-1821
> Project: XalanJ2
> Type: Bug
> Components: Serialization
> Versions: 2.5
> Environment: Operating System: Other
> Platform: All
> Reporter: Alick Buckley
> Assignee: Xalan Developers Mailing List
> Priority: Minor
>
> 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
> [EMAIL PROTECTED]'ORDER']/@value}">
> <Customer CustNumber="{/rdml:function/rdml:fields/rdml:field
> [EMAIL PROTECTED]'CUSTNUM']/@value}">
> <CustName><xsl:value-of
> select="/rdml:function/rdml:fields/rdml:[EMAIL
> PROTECTED]'NAME']/@value"/></CustName>
> <Street><xsl:value-of
> select="/rdml:function/rdml:fields/rdml:field
> [EMAIL PROTECTED]'STREET']/@value"/></Street>
> <City><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
> [EMAIL PROTECTED]'CITY']/@value"/></City>
> <State><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
> [EMAIL PROTECTED]'STATE']/@value"/></State>
> <PostCode><xsl:value-of
> select="/rdml:function/rdml:fields/rdml:[EMAIL
> PROTECTED]'ZIP']/@value"/></PostCode>
> </Customer>
> <OrderDate><xsl:value-of select="/rdml:function/rdml:fields/rdml:field
> [EMAIL PROTECTED]'ORDDTE']/@value"/></OrderDate>
> </SalesOrder>
> </Orders>
> ==============================================================================
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]