tags:

views:

44

answers:

2

Hi all, I am trying to create a html based template with xslt transformation.The string result returned by the transformer is perfectly fine.but when i try to send it to display, the browser is not interpreting it. The output looks like<html><body>...</body></html>. when i do view source it is displaying &lt;html&gt;... How can i resolve it?Please help. Thanks in advance

+1  A: 

Did you specify the output method correctly? It should be set to HTML:

<xsl:output method="html" encoding="UTF-8" />
0xA3
Yes i have used output method 'html'. When i print the string in server console it is properly printing html tags,but in browser it is not interpreted.
sindhu
@sindhu: Can you show your stylesheet and the code that you use to call it and save the output?
0xA3
A: 

<xsl:output value="html"/> <xsl:template match="mail[@type='pinReset']">
<html><body> <xsl:variable name="userService" select="java:new()"/> <i><u>Message body </u><xsl:value-of select="mailMessage/mail/body/prefix"/></i> <a><xsl:attribute name="href"> <xsl:value-of select="java:getResetPinUrl($userService)"/></xsl:attribute> reset pin </a> <i><xsl:value-of select="mailMessage/body/suffix"/></i><br/>
</body> </html> </xsl:template> </xsl:stylesheet>

This is my XSl.

public String getXformedString(int type){ String xFormedString = ""; String xsltFile = "D:\\SitesContent\\sitescontent_war\\JavaSource\\com\\tgt\\mobile\\gc\\controller\\email.xsl"; String xmlFile="D:\\SitesContent\\sitescontent_war\\JavaSource\\com\\tgt\\mobile\\gc\\controller\\emailBody.xml"; StringWriter stWr = new StringWriter(); File xsltfile = new File(xsltFile); File xmlfile = new File(xmlFile); Source xmlSource = new StreamSource(xmlfile); Source xsltSource = new StreamSource(xsltfile); Result result = new StreamResult(stWr); TransformerFactory transFact = TransformerFactory.newInstance(); try { Transformer transformer= transFact.newTransformer(xsltSource); transformer.setParameter("type",new Integer(type)); transformer.transform(xmlSource, result); xFormedString = stWr.toString(); System.out.println("Str->"+xFormedString); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block
e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return xFormedString; }

This is the code to get the formed string from xml and xslt.

sindhu