views:

287

answers:

1

I'm trying to figure out how to use the struts2 XSL ResultType. I just can't figure out how it is supposed to work and aside from the official documentation, I've found maybe two articles online that tried to explain it (unsuccessfully for me).

My understanding of how it works is I create an xsl stylesheet, then I have a struts action setup that somehow returns an xml document. The action applies the assigned xsl stylesheet to the xml document and it outputs the desired xhtml to the browser. Is this correct?

If my understanding is correct, can someone provide a clear, concise explanation of how I set up my action class to return an xml document that can be transformed?

If my understanding is incorrect, can someone please correct me and explain how it is supposed to be used?

Thanks!

A: 

The XSLTResult internally produces the XML to postprocess with the given template. If you use an XSLT file that doesn't actually transform anything, you get the raw result:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  <xsl:template match="result">
    <xsl:copy-of select="."></xsl:copy-of>
  </xsl:template>
</xsl:stylesheet>

I use this template for all my XML results. If this seems silly to you, I have to agree. I found a number of tutorials on the interwebs which said that you could just drop the locationparameter from the result definition, but this led to the following error for me:

javax.xml.transform.TransformerException: Operation not supported. - [unknown location]

Hanno Fietz