Results 1 to 3 of 3
  1. #1
    smarty_m2002 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default 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>&amp;#163;</currencysymbol>"+
            "<symbol>&gt;</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>&lt;hello&gt;</xsl:text><xsl:text>goodbye</xsl:text>
        <xsl:text
    disable-output-escaping="yes">&lt;hello&gt;</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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: XSLT | disable-output-escaping adding a new line to the output

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    smarty_m2002 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: XSLT | disable-output-escaping adding a new line to the output

    Thanks Db for the guidance notes.

    Anyone any replies to my question?

Similar Threads

  1. Adding output to txt file
    By Sean2012 in forum New To Java
    Replies: 3
    Last Post: 04-24-2012, 03:36 PM
  2. Command line text output
    By Eleeist in forum New To Java
    Replies: 5
    Last Post: 01-23-2012, 09:54 PM
  3. Adding line numbers to code in output file
    By misterwebb in forum New To Java
    Replies: 2
    Last Post: 02-14-2011, 12:37 AM
  4. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  5. how to print output on same line in 'while loop'?
    By acidblue in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •