Results 1 to 3 of 3
- 05-02-2012, 07:15 PM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
XSLT | disable-output-escaping adding a new line to the output
When I use disable-output-escaping="yes" in the xslt with JDOM (1.0 or 2.0), it adds an additional newline character to the escaped text .
Any idea why?
Example, I get following output the the following test code (newline added to 'The cost is' {newline} > {newline} 5
Output:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
The cost is
>
5
So it's
£
6
<hello>goodbye
<hello>
goodbye
</body>
</html>
Java Code:package com.test; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.*; import javax.xml.transform.stream.StreamSource; import java.io.*; import org.jdom.*; import org.jdom.input.SAXBuilder; import org.jdom.output.*; import org.jdom.transform.*; import org.xml.sax.SAXException; public class XsltTest { static String thexml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "+ "<xmlTag version=\"2.0\" siteId=\"5373\"> "+ "<params>"+ "<currency>pounds</currency>"+ "<currencysymbol>&#163;</currencysymbol>"+ "<symbol>></symbol>"+ "</params>"+ "</xmlTag>"; public static void main(String args[]){ try { // another(); xmsttest(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void xmsttest() throws Exception { Document jdomResult = stringToDom(thexml); System.out.println("Before transformation:\n" + thexml); XSLTransformer transformer = new XSLTransformer(new File("C:\\tmp\\tmp1\\template.xml")); Document xmlDocTransformed = transformer.transform(jdomResult); printXml(xmlDocTransformed); // System.out.println("****************\n"+xmlDocTransformed); } public static void printXml(Document xmlDocTransformed){ Format format = Format.getPrettyFormat(); // format.setIgnoreTrAXEscapingPIs(true); XMLOutputter outputter = new XMLOutputterExtendeded(format); String transformedxml = outputter.outputString(xmlDocTransformed); System.out.println("After transformation:\n" + transformedxml); } public static Document stringToDom(String xmlSource) throws SAXException, ParserConfigurationException, IOException, JDOMException { SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(new StringReader(xmlSource)); return doc; } }
template.xml
XML Code:<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> The cost is <xsl:value-of select="xmlTag/params/symbol" disable-output-escaping="yes" /> 5 So it's <xsl:value-of select="xmlTag/params/currencysymbol" disable-output-escaping="yes" />6 <xsl:text><hello></xsl:text><xsl:text>goodbye</xsl:text> <xsl:text disable-output-escaping="yes"><hello></xsl:text><xsl:text> goodbye</xsl:text> </body> </html> </xsl:template> </xsl:stylesheet>Last edited by smarty_m2002; 05-03-2012 at 11:38 AM.
- 05-02-2012, 07:23 PM #2
Re: XSLT | disable-output-escaping adding a new line to the output
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-03-2012, 11:39 AM #3
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Adding output to txt file
By Sean2012 in forum New To JavaReplies: 3Last Post: 04-24-2012, 03:36 PM -
Command line text output
By Eleeist in forum New To JavaReplies: 5Last Post: 01-23-2012, 09:54 PM -
Adding line numbers to code in output file
By misterwebb in forum New To JavaReplies: 2Last Post: 02-14-2011, 12:37 AM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
how to print output on same line in 'while loop'?
By acidblue in forum New To JavaReplies: 5Last Post: 12-13-2007, 02:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks