Subject: RE: Transformer adds unwanted newlines
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 3 Oct 2008 14:45:04 +0100
|
You're doing a two-stage transformation here: first a transformation using a
stylesheet, which then feeds its output in the form of a SAXSource to a JAXP
identity transform which converts the SAXSource to a StreamResult.
I don't know why you're doing this or why it adds newlines, but it does mean
that the xsl:output is going to be ignored because the output of the
stylesheet is not serialized.
What happens if you remove the (apparently unnecessary) second step?
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: John English [mailto:je@xxxxxxxxxxxxxx]
> Sent: 03 October 2008 13:23
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: Transformer adds unwanted newlines
>
> David Carlisle wrote:
> >>Anyone got any ideas what I can do about this?
> > but ignoring indent=no sounds less likely, are you sure you
> don't have
> > another xsl:output somewhere, or that you are not outputing an XMl
> > tree that is then being serialised by some other JDK methord rather
> > than being serialised by XSLT?
>
> No other xsl:output, and all I do in the transform is this:
>
> SAXParserFactory spf = SAXParserFactory.newInstance();
> spf.setNamespaceAware(true);
> SAXParser parser = spf.newSAXParser();
> reader = parser.getXMLReader();
> stf = (SAXTransformerFactory) TransformerFactory.newInstance();
> String s = serializeTree();
> System.out.println("DEBUG: " + s); // <------- DEBUG
> InputSource input = new InputSource(new StringReader(s));
> filter = stf.newXMLFilter(new StreamSource(stylesheet));
> filter.setParent(reader);
> StreamResult result = new StreamResult(response.getWriter());
> Transformer transformer = stf.newTransformer();
> SAXSource transformSource = new SAXSource(filter, input);
> transformer.transform(transformSource, result);
>
> At the point where the DEBUG output is, the serialized tree
> is as I've described it; the extra newlines appear in the
> output also as described.
>
> In the meantime I have kludged up a workaround when I serialise the
> tree:
>
> if (tagName.equals("pre")) {
> d = d.replaceAll("<br[^>]*>","\n");
> }
>
> This works but it offends my sensibilities!
>
> Thanks,
>
> ----------------------------------------------------------------------
> John English | mailto:je@xxxxxxxxxxxxxx
> Senior Lecturer | http://www.it.bton.ac.uk/staff/je
> School of Computing & MIS | "Those who don't know their history
> University of Brighton | are condemned to relive it" (Santayana)
> ----------------------------------------------------------------------
|