0

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
  • Can you show us your stylesheet? Commented May 7, 2010 at 10:32

2 Answers 2

1

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

<xsl:output method="html" encoding="UTF-8" />
Sign up to request clarification or add additional context in comments.

2 Comments

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: Can you show your stylesheet and the code that you use to call it and save the output?
0

<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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.