You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Jarno Elovirta <ja...@codeonline.com> on 2000/07/13 11:14:53 UTC

RE: How to use your own serializers with Xalan-J? - Problem with Xalan's own Formatters

yes, this works. but i get character escaping problems when i set the output
to use a Writer. e.g.

  //set output
  BufferedWriter output = new BufferedWriter(new
OutputStreamWriter(System.out));
  //create processor
  XSLTProcessor processor = XSLTProcessorFactory.getProcessor ();
  //create Xalan's own XML serializer
  FormatterToXML serializer = new FormatterToXML(output);
  //set the result target to the serializer above
  XSLTResultTarget target = new XSLTResultTarget(serializer);
  //do it, baby!
  processor.process(new XSLTInputSource(new BufferedReader(new
FileReader(args[0]))),
                    new XSLTInputSource(new BufferedReader(new
FileReader(args[1]))),
                    target);
  //close the writer
  output.close();

and when i use it with a stylesheet e.g.

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" />

  <xsl:template match="/">
    <foo>
      <xsl:text>bar &amp; baz</xsl:text>
    </foo>
  </xsl:template>

  </xsl:stylesheet>

the output is

  [c:\dev\hdml]java -cp
c:\lang\dev\xerces-1_1_2\xerces.jar;c:\lang\dev\xalan_1_1\xalan.jar;c:\dev\c
lasses com.codeonline.survey.util.CommandLineHDML test.xsl test.xsl
  <?xml version="1.0" encoding="UTF-8"?>
  <foo>bar & baz</foo>

which is nice except that the & hasn't been escaped. this *doesn't* occur if
i use an OutputStream instead of a Writer. my FormatterToHDML works if i use
it with an OutputStream and escapes $ like it should, but with a Writer it
behaves like FormatterToXML and FormatterToHTML. is this a bug in Xalan or
am i just doing something with the Formatters that shouldn't be done?

Jarno Elovirta

-----Original Message-----
From: Sobeck, David [mailto:david.sobeck@thinklinkinc.com]
Sent: 12. heinäkuuta 2000 20:21
To: 'xalan-dev@xml.apache.org'
Subject: RE: How to use your own serializers with Xalan-J?

I did this for WML by specializing FormatterToXML and supplying that to the
processor. I think that you will find that consolidating this publishing
step (rather than handling SAX events) is an efficiency win.
The Xalan Formatter classes are supposed to be superceded by thhe Xerces
Serializers, but the Xalan classes are more efficient, and the Xerces
XMLSerializer is final (I wish it weren't).
XSLTProcessor xt = XSLTProcessorFactory.getProcessor ();
WAPSerializer serializer = new WAPSerializer (dest);
XSLTResultTarget target = new XSLTResultTarget (serializer);
xt.process (new XSLTInputSource (source, new XSLTInputSource(styleSheet),
result);