user8185075
user8185075

Reputation: 48

How to convert XSLT to plain text with encoded data?

I am trying to convert a XSLT file to plain text. The problem is XSLT file has encoded values e.g, & is & and Transformer factory outputs encoded value. Is there a better other than using XML decoder and then covert to plain text?

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(XSLT_Source));       
transformer.setOutputProperty("media-type", "text/plain");
transformer.transform(new StreamSource(XSLT_Source), new StreamResult(new FileOutputStream(outputTrager)));  

Upvotes: 0

Views: 476

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167401

If you can edit the stylesheet make sure it uses <xsl:output method="text"/>. If you want to set that programmatically with the JAXP API then see https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/OutputKeys.html#METHOD, you need to set

transformer.setOutputProperty(javax.xml.transform.OutputKeys.METHOD, "text");

Upvotes: 1

Related Questions